different types of waits in selenium webdriver and explain it with example?
Answers
Answered by
0
Hey buddy I'm gonna explain fully about types of waits in selenium webdriver ,,..so listen carefully
Sometime our test fails due to page was not loaded with all element because of slow internet connection or may be the poor response time. So now question is how to handle this problems.? And when to use which wait in selenium.?
There is 2 different way to handle this using waits:
1. Implicit Waits
2. Explicit Waits
1. Implicit Waits
WebDriver waits for an element if they are not immediately available. So, WebDriver does not throw NoSuchElementException immediately. This is known as implicitlyWait().
Disadvantages:
◆ In any case, it blindly wait for given seconds.
◆ Once set, the implicit wait is set for the life of the WebDriver object instance.
2. Explicit Waits
Thread.sleep()
This is to wait the running program for sometime, this can be done using:
Ex.- Thread.sleep(3600).
Disadvantages:
◆ In this case, it again blindly wait for given seconds. It is not a better way because if the the element is present within this given wait time, program does not move further until the wait time finished.
◆ Some computers are slow, an element may not show up in a slow computer within the given wait time.
WARNING:
● Do not mix implicit and explicit waits. Doing so can cause unpredictable wait times. For example setting an implicit wait of 10 seconds and an explicit wait of 15 seconds, could cause a timeout to occur after 20 seconds.
● Never ever use both implicit wait and explicit wait on same driver. Its not good practice. Implicit wait is implemented at driver level where as Explicit wait is implemented at language binding level (e.g. Java, c# etc.)
PageLoadTimeout Command:
Purpose: Sets the amount of time to wait for a page load to complete before throwing an error. If the timeout is negative, page loads can be indefinite.
SetScriptTimeout Command:
Purpose: Sets the amount of time to wait for an asynchronous script to finish execution before throwing an error. If the timeout is negative, then the script will be allowed to run indefinitely.
THANK YOU SO MUCH FOR ASKING THIS TYPE OF QUESTION ..IM PROUD OF U DEAR
Sometime our test fails due to page was not loaded with all element because of slow internet connection or may be the poor response time. So now question is how to handle this problems.? And when to use which wait in selenium.?
There is 2 different way to handle this using waits:
1. Implicit Waits
2. Explicit Waits
1. Implicit Waits
WebDriver waits for an element if they are not immediately available. So, WebDriver does not throw NoSuchElementException immediately. This is known as implicitlyWait().
Disadvantages:
◆ In any case, it blindly wait for given seconds.
◆ Once set, the implicit wait is set for the life of the WebDriver object instance.
2. Explicit Waits
Thread.sleep()
This is to wait the running program for sometime, this can be done using:
Ex.- Thread.sleep(3600).
Disadvantages:
◆ In this case, it again blindly wait for given seconds. It is not a better way because if the the element is present within this given wait time, program does not move further until the wait time finished.
◆ Some computers are slow, an element may not show up in a slow computer within the given wait time.
WARNING:
● Do not mix implicit and explicit waits. Doing so can cause unpredictable wait times. For example setting an implicit wait of 10 seconds and an explicit wait of 15 seconds, could cause a timeout to occur after 20 seconds.
● Never ever use both implicit wait and explicit wait on same driver. Its not good practice. Implicit wait is implemented at driver level where as Explicit wait is implemented at language binding level (e.g. Java, c# etc.)
PageLoadTimeout Command:
Purpose: Sets the amount of time to wait for a page load to complete before throwing an error. If the timeout is negative, page loads can be indefinite.
SetScriptTimeout Command:
Purpose: Sets the amount of time to wait for an asynchronous script to finish execution before throwing an error. If the timeout is negative, then the script will be allowed to run indefinitely.
THANK YOU SO MUCH FOR ASKING THIS TYPE OF QUESTION ..IM PROUD OF U DEAR
Similar questions
Environmental Sciences,
7 months ago
English,
7 months ago
Math,
1 year ago
Social Sciences,
1 year ago