Last week , we had an interesting discussion about the poll interval in Selenium Wait and there are some different opinions had been given 🙂
The questions to discuss:
Given implicitWait = 10 s it set. and an element will display after 5 seconds.
does Webdriver keep polling the element if it cannot find it ? of course only within 10s or an Exception will be raised.
If Yes, what is the default value of poll interval in ImplicitWait ?
does it depends on browser specific ?
what is default value for poll interval in ExplicitWait ? is it the same for all language implementation such as Java, Python, Ruby… ?
1. does Webdriver keep polling the element or it just wait for certain of time defined in implicitWait ?
here is implementation of Webdriver implicitly_wait() for Python language:
def implicitly_wait(self, time_to_wait):
“””
Sets a sticky timeout to implicitly wait for an element to be found, or a command to complete. This method only needs to be called one time per session. To set the timeout for calls to execute_async_script, see set_script_timeout.
:Args:
– time_to_wait: Amount of time to wait (in seconds)
:Usage:
driver.implicitly_wait(30)
“””
if self.w3c:
self.execute(Command.SET_TIMEOUTS, {‘implicit’: int(float(time_to_wait) * 1000)})
else:
self.execute(Command.IMPLICIT_WAIT, {‘ms’: float(time_to_wait) * 1000})
So , It will send a command IMPLICIT_WAIT to RemoteWebDriver. This term may also refer to a specific browser that implements the wire protocol directly, such as the FirefoxDriver or ChromeDriver.
IMPLICIT_WAIT = “implicitlyWait”
Let check what is done with this command:
The Client will send “implicitlyWait” command to RemoteWebDriver. this is actually a REST request over JsonWireProtocol:
POST /session/:sessionId/timeouts/implicit_wait
Set the amount of time the driver should wait when searching for elements. When searching for a single element, the driver should poll the page until an element is found or the timeout expires, whichever occurs first. When searching for multiple elements, the driver should poll the page until at least one element is found or the timeout expires, at which point it should return an empty list.
If this command is never sent, the driver should default to an implicit wait of 0ms.
-
-
- URL Parameters:
:sessionId – ID of the session to route the command to.
-
- JSON Parameters:
ms –Â{number} The amount of time to wait, in milliseconds. This value has a lower bound of 0.
-
Ok. We found the answer for the first question. Webdriver does poll the element during defined timeout.Â
2. What is the poll interval value of implicitWait ?
The implicitlyWait is executed by specific driver. So the poll interval will depends on that browser driver like FirefoxDriver or ChromeDriver.
In my experience , it seems less than 1 seconds, may be as quick as possible.
So  if implicitWait = 10 s. and an element displays after 5 seconds , then element.click() can be done at 5 s.
3. what is default value for poll interval in ExplicitWait ?
500ms in Python, Java, Dotnet:
POLL_FREQUENCY = 0.5 # How long to sleep inbetween calls to the method
or 200ms in Ruby:
DEFAULT_TIMEOUT = 5
DEFAULT_INTERVAL = 0.2
or 0 ms in Javascript (there is no such thing as “poll frequency” in javascript selenium bindings. it performs the check as quick as possible.)
In summary, the poll interval value is depends on language binding.