java - Selemium webdriver: How many times does a driver try to find element with an implicit wait timeout? -


say have code this:

webdriver driver = new chromedriver(); driver.manage().timeout().implicitwait(10, timeunit.seconds); driver.findelement(by.id("nothing")); 

i have trouble understand line in selenium doc: implicit wait tell webdriver poll dom amount of time when trying find element or elements if not available.

so mean driver wait 10 seconds before first try find element? or mean driver find element first, if nothing found, wait 10 seconds, find again, if not found throw timeoutexception? driver tries find element twice in total?

you can clear things logging json wire protocol commands chrome service logs. let's have python code (for sake of example):

from selenium import webdriver  driver = webdriver.chrome(service_log_path="/tmp/log") driver.get("http://www.google.com")  driver.find_element_by_css_selector("strange.non.existing.element")  driver.quit() 

here nosuchelementexception instantly , in /tmp/log have:

[2.134][info]: command navigate {    "sessionid": "920fbde18d13995672cbbdd0a15e905a",    "url": "http://www.google.com" } [2.195][info]: waiting pending navigations... [2.239][info]: done waiting pending navigations [2.593][info]: waiting pending navigations... [3.704][info]: done waiting pending navigations [3.704][info]: response navigate [3.706][info]: command findelement {    "sessionid": "920fbde18d13995672cbbdd0a15e905a",    "using": "css selector",    "value": "strange.non.existing.element" } [3.706][info]: waiting pending navigations... [3.706][info]: done waiting pending navigations [3.720][info]: waiting pending navigations... [3.720][info]: done waiting pending navigations [3.720][info]: response findelement no such element   (session info: chrome=43.0.2357.134) 

now, let's set implicit wait 10 seconds:

from selenium import webdriver  driver = webdriver.chrome(service_log_path="/tmp/log") driver.get("http://www.google.com")  # setting implicit wait driver.implicitly_wait(10)  driver.find_element_by_css_selector("strange.non.existing.element")  driver.quit() 

now, if logs:

[1.996][info]: command navigate {    "sessionid": "657700804d0d8f71b2bfee6dc222c289",    "url": "http://www.google.com" } [2.073][info]: waiting pending navigations... [2.106][info]: done waiting pending navigations [2.477][info]: waiting pending navigations... [3.371][info]: done waiting pending navigations [3.371][info]: response navigate [3.374][info]: command setimplicitwait {    "ms": 10000.0,    "sessionid": "657700804d0d8f71b2bfee6dc222c289" } [3.374][info]: response setimplicitwait [3.376][info]: command findelement {    "sessionid": "657700804d0d8f71b2bfee6dc222c289",    "using": "css selector",    "value": "strange.non.existing.element" } [3.376][info]: waiting pending navigations... [3.376][info]: done waiting pending navigations [13.410][info]: waiting pending navigations... [13.410][info]: done waiting pending navigations [13.410][info]: response findelement no such element   (session info: chrome=43.0.2357.134) 

as, can see there 1 findelement command sent webdriver, response got , nosuchelementexception thrown after 10 seconds delay.


what happens internally described in docs here: 10 seconds polls dom trying find desired element ignoring nosuchelementexception. when time , no element found yet throw nosuchelementexception:

an implicit wait tell webdriver poll dom amount of time when trying find element or elements if not available. default setting 0. once set, implicit wait set life of webdriver object instance.


Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -