Wait!!!
These four letters can drive you crazy if you are having a bad day using Webdriver...
Thus if you are reading this article you are already in the middle of one bad bad day...thus I'll cut the crap and go directly into the ways you can add waits using webdriver:
These four letters can drive you crazy if you are having a bad day using Webdriver...
Thus if you are reading this article you are already in the middle of one bad bad day...thus I'll cut the crap and go directly into the ways you can add waits using webdriver:
Type 1 - Using driver.manager.timeouts()
Implicit Waits - When you set this wait, webdriver would wait for this amount of time before failing any command.
- Syntax - driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
- Example - Webdriver is looking to find an element using an xpath and its not able to find it, webdriver waits for 10 seconds before trying to find the element and thus failing if it still can't find the element after 10 seconds
Page Load Timeouts - When you set this wait, webdriver would wait for this amount of time to declare page load timeouts
- Syntax - driver.manage().timeouts().pageLoadTimeout(100, SECONDS);
- Example - Let's say we are navigating from one page to another, when we reach the next page in line, we might need to wait for some time so that all the elements on the page would load and then execute the commands. In this case, the above command is useful
Script timeouts - When you set this wait, webdriver would wait for this amount of time to declare script timeouts. It would 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.
- Syntax - driver.manage().timeouts().setScriptTimeout(100,SECONDS);
- Example - Let's say an asynchronous script is running and you need to wait till it completes, using the above command, we can wait till 100 seconds for the script to complete its execution.
Comments