1

Let's consider time out is 10 sec.

Element found in 3 sec.

In all three wait cases what would be response of webdriver

Muthu Kumaran
  • 17,682
  • 5
  • 47
  • 70
IMLucky
  • 11
  • 2

1 Answers1

0

In general, despite of what kind of method you choose, program will continue once element was found.

The difference between whose three methods is WHEN will the driver find the element.

  1. Difference between Fluent wait and Explicit wait (in Java) is that you can set poll interval and ignored exception with Fluent wait.
    (But in python, when using WebDriverWait class, those settings are optional. In most case, you could use this class as the combination of Fluent and Explicit implementation. see https://stackoverflow.com/a/25784321/8186183)
  2. Difference between Explicit and Implicit wait is that Implicit waiting time is a global setting option. It will take effect every time you call find element or other expected conditions.

see also Differences between impilicit, explicit and fluentwait

And I just make a little example compared these there methods with python (If there's any different result using Java to implement this, please let me know)
**I build a blank page and a piece of scripts which product a block with id="new_elem" after 3 seconds.**And I use PhantomJS as selenium driver.

I would like to present the time those methods processing the find elements task first.

Fluent wait, 1s interval: waited 3.076176 seconds
Fluent wait, 5s interval: waited 5.587320 seconds
Explicit wait, 10s wait time: waited 3.105178 seconds
Implicit wait, 10s wait time: waited 3.138179 seconds

1.1 Fluent Wait with 1 second interval

start = time.time()
driver.get('http://127.0.0.1:5000')
element = WebDriverWait(driver, 10, poll_frequency=1).until(EC.presence_of_element_located((By.ID, 'new_elem')))
print("Fluent wait, 1s interval: waited %f seconds" % (time.time()-start))

After 3 seconds, the driver found the element.

1.2 Fluent Wait with 5-second interval

start = time.time()
driver.get('http://127.0.0.1:5000')
element = WebDriverWait(driver, 10, poll_frequency=5).until(EC.presence_of_element_located((By.ID, 'new_elem')))
print("Fluent wait, 5s interval: waited %f seconds" % (time.time()-start))

The driver did not find the element immediately after the element shows up, but after a 5-second interval.

2. Explicit Wait with 10-second wait time

start = time.time()
driver.get('http://127.0.0.1:5000')
element = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, 'new_elem')))
print("Explicit wait, 10s wait time: waited %f seconds" % (time.time()-start))

In default, the polling interval of WebDriverWait is 0.5 seconds. So the driver found the element right after 3 seconds.

3 Implicit Wait with 10-second wait time

start = time.time()
driver.implicitly_wait(10)
driver.get('http://127.0.0.1:5000')
element = driver.find_element_by_id('new_elem')
print("Implicit wait, 10s wait time: waited %f seconds" % (time.time()-start))

Please notice, implicitly waiting time is a global setting option. Once set, whenever call find_element method, it will wait up to waiting time before find the element. But once it find the target, it will return the result and wait no more time.
Also, you could not set polling interval with implicitly wait. It will just keep trying polling certain elements from DOM with short time intervals.

Barry Zhai
  • 88
  • 8
  • My question is regarding remaining 7 sec weather webdriver remain idle or it will execute next command in all these wait cases. – IMLucky Aug 22 '17 at 10:25
  • @IMLucky **It will execute next command immediately in all cases** once it find the element. You can see that in the waiting time printed. In all 3 (or 4) cases, once the driver find the element using polling request, it executes followed print function. So if the driver remain idle, the waiting time printed will be 10s instead of 3s. – Barry Zhai Aug 22 '17 at 11:14