20

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.

Ajinkya
  • 22,324
  • 33
  • 110
  • 161
someone be there
  • 213
  • 1
  • 2
  • 9

3 Answers3

32

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.

Louis
  • 146,715
  • 28
  • 274
  • 320
0

For implicit wait always default wait it ZERO. , you can check it here :

Selenium Webdriver diff. waits

And if you set custom time then web driver will wait to get element till that time and if element does not found till that time then only web driver will throw exception.

Helping Hands
  • 5,292
  • 9
  • 60
  • 127
0

The Selenium documentation is very much unclear on these timeouts.

  1. According to this the default timeout of the implicit-wait is 0
  2. According to this any page that does not load in 60s will return http communication timeout unless you explicitly overwrite the timeout.
  3. Unfortunately, I did not find any reference to provide on ScriptTimeout. But, it's defaults to 0 according to my knowledge and experience. Will update you with any reference later
Saifur
  • 16,081
  • 6
  • 49
  • 73
  • What about that script timeout? What is the value? I am facing this problem right now. My script fails on page load and I dont know why. If it is script timeout or pageload timeout or what... Hope somebody knows. – Čamo Mar 22 '21 at 08:57
  • @Čamo as I mentioned the scriptTimeout is also 0. You can definitely set it for async script execution. Without knowing much about the implementation cannot really help. Are you executing any javascript that fails? – Saifur Mar 22 '21 at 21:31
  • I mean page is blank on screenshot. No content at all. I looks like slow connection sometimes cause the test sometimes pass and sometimes not. Still the same test with the same code. – Čamo Mar 23 '21 at 09:33