Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set Selenium Python WebDriver default timeout?

Trying to find a good way to set a maximum time limit for command execution latency in Selenium Python WebDriver. Ideally, something like:

my_driver = get_my_driver() my_driver.set_timeout(30) # seconds my_driver.get('http://www.example.com') # stops / throws exception when time is over 30     seconds 

would work. I have found .implicitly_wait(30), but I'm not sure if it results in the desired behavior.

In case it is useful, we are specifically using the WebDriver for Firefox.

EDIT

As per @amey's answer, this might be useful:

ff = webdriver.Firefox() ff.implicitly_wait(10) # seconds ff.get("http://somedomain/url_that_delays_loading") myDynamicElement = ff.find_element_by_id("myDynamicElement") 

However, it is not clear to me whether the implicit wait applies both to get (which is the desired functionality) and to find_element_by_id.

Thanks very much!

like image 641
Juan Carlos Coto Avatar asked Jul 08 '13 17:07

Juan Carlos Coto


People also ask

What is set page load timeout Selenium Python?

WebDriver. Timeouts pageLoadTimeout(long time, java. util. concurrent. TimeUnit unit) Sets the amount of time to wait for a page load to complete before throwing an error.

What is default time out time in Selenium IDE?

For page loads: 300 seconds. For script timeouts: 30 seconds.


2 Answers

In python, the method to create a timeout for a page to load is:

Firefox and Chromedriver:

driver.set_page_load_timeout(30) 

Other::

driver.implicitly_wait(30) 

This will throw a TimeoutException whenever the page load takes more than 30 seconds.

like image 94
Juan Carlos Coto Avatar answered Sep 28 '22 13:09

Juan Carlos Coto


The best way is to set preference:

fp = webdriver.FirefoxProfile() fp.set_preference("http.response.timeout", 5) fp.set_preference("dom.max_script_run_time", 5) driver = webdriver.Firefox(firefox_profile=fp)  driver.get("http://www.google.com/") 
like image 24
Nima Soroush Avatar answered Sep 28 '22 13:09

Nima Soroush