Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The default value of timeouts on selenium webdriver

I am interested in the default value of timeouts on selenium webdriver. ImplicitlyWait, SetPageLoadTimeout and SetScriptTimeout. Because I want to know, Do I need to set a values for those timeouts? or the default value is good for selenium webdriver working. But I cannot find a correct answer, someone say the default value is 0, and other one say it is 30 sec.

like image 514
someone be there Avatar asked May 08 '15 02:05

someone be there


1 Answers

These three timeouts are managed by the server-side of the Selenium equation. Your script, be it in Java, Python, Ruby, C#, or whatever, is a client that sends commands to a server that lives in the browser. (There may be an intermediary that relays commands to the browser, like Selenium grid. Unfortunately, it is also sometimes called a "server".)

The WebDriver specification, which was derived from Selenium has settled on the following values:

  • For implicit waits: 0 seconds. This means that if a selenium command does not find an element immediately, it reports immediately, rather than wait until an element is found.

  • For page loads: 300 seconds.

  • For script timeouts: 30 seconds.

(The specification gives the values in milliseconds. I've converted them to seconds for ease of reading.)

Selenium now follows the WebDriver specification.


In the past Selenium has used other values for these, however. For instance, the Firefox driver used to define its timeouts like this:

  • The implicit wait timeout is set to 0 by default. This means that if a command that finds elements does not find anything, it won't wait.

  • The page load timeout is set to -1 by default. This means that Selenium will wait indefinitely for the page to load.

    What Saifur found is not the same as the page load timeout. That's a timeout between the Selenium client and the Selenium server, which is not particularly well explained on the page Saifur found.

  • The script timeout is set to 0 by default. A comment in the source code explains:

    The amount of time, in milliseconds, this session should wait for asynchronous scripts to finish executing. If set to 0, then the timeout will not fire until the next event loop after the script is executed. This will give scripts that employ a 0-based setTimeout to finish.

    So even if it set to zero, an asynchronous script can still execute but it has to complete before Selenium's timeout gets a chance to run again.

This is from the code that Selenium uses for Firefox. The other browsers use different code bases but they are supposed to behave consistently, at least with regards to things that are proper to Selenium itself, like these timeouts. So the values and their interpretations should be the same for other browsers too.

like image 173
Louis Avatar answered Sep 29 '22 11:09

Louis