Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make Selenium wait 10 seconds

Yes I know the question has been asked quite often but I still don't get it. I want to make Selenium wait, no matter what. I tried these methods

driver.set_page_load_timeout(30) driver.implicitly_wait(90) WebDriverWait(driver, 10) driver.set_script_timeout(30) 

and other things but it does not work. I need selenium to wait 10 seconds. NO not until some element is loaded or whatever, just wait 10 seconds. I know there is this

try:    element_present = EC.presence_of_element_located((By.ID, 'whatever'))    WebDriverWait(driver, timeout).until(element_present) except TimeoutException:     print "Timed out waiting for page to load" 

I do not want that.

If waiting for some seconds is to much (not achievable) for selenium, what other (python) library's/programs would be capable to achieve this task? With Javas Selenium it does not seem to be a problem...

like image 588
hansTheFranz Avatar asked Jul 27 '17 10:07

hansTheFranz


People also ask

How do I make Selenium wait 10 seconds?

We can make Selenium wait for 10 seconds. This can be done by using the Thread. sleep method. Here, the wait time (10 seconds) is passed as a parameter to the method.

What is the Selenium command to delay test execution for 10 seconds?

Implicit Wait in Selenium Once we set the time, the web driver will wait for the element for that time before throwing an exception. Selenium Web Driver has borrowed the idea of implicit waits from Watir. In the below example we have declared an implicit wait with the time frame of 10 seconds.

How do I pause Selenium test?

pause (time in milliseconds) - Selenium IDE command Special feature: If you use pause | 0 or simply pause without any number then the execution pauses until the user clicks the RESUME button.


1 Answers

All the APIs you have mentioned is basically a timeout, so it's gonna wait until either some event happens or maximum time reached.

set_page_load_timeout - 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.

implicitly_wait - Specifies the amount of time the driver should wait when searching for an element if it is not immediately present.

set_script_timeout - 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.

for more information please visit following page. (documention is for JAVA binding, but functionality should be same for all the bindings) https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/WebDriver.Timeouts.html#implicitlyWait-long-java.util.concurrent.TimeUnit-

So, if you want to wait selenium (or any script) 10 seconds, or whatever time. Then the best thing is to put that thread to sleep.

In python it would be

import time  time.sleep(10) 

In JAVA it would be

The simple way to do this is using

    try {         Thread.sleep(10*1000);     } catch (InterruptedException e) {         e.printStackTrace();     } 
like image 169
Gaurang Shah Avatar answered Oct 04 '22 06:10

Gaurang Shah