Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Selenium wait.until method

Hello fellow programmers, I have a simple question .

Is wait = WebDriverWait(browser, 10) equivalent to time.sleep(10)?

I’m developing this selenium app and sometimes the server traffic is quite massive which leads to different loading times when moving from page to page . I found time.sleep(N) isn’t efficient but if I use the wait.until EC block will the code execute once the condition is met ?
It won’t waste time if use wait = WebDriverWait(browser, 60) and the page loads in 3 seconds ?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The hardcoded pause of time.sleep(10) and the explicit wait of wait = WebDriverWait(browser, 10) are definitely not the same.
The hardcoded pause of time.sleep(10) will pause execution of the code for the period of 10 seconds with no conditions.
The explicit wait of wait = WebDriverWait(browser, 10) will poll the web page until the specified condition is met. Once the condition is met your code will continue execution immediately.
For example if you defined your explicit wait to wait until element located by div.selected is visible, Selenium will poll the DOM every some predefined period, lets say every 100 milliseconds and when it founds such element visible the wait will finish and your code will continue execution.
In case the condition was not met up to the defined timeout, in the example above it is 10 seconds, Selenium will throw TimeoutException Exception.
There are a lot of tutorials about this, for example here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading