The implicit wait is equivalent to setting the global wait, setting the time-out for all elements when the element is positioned.
The implicit wait allows Webdriver to poll the DOM every other time for an element or element array, if the element or array is not immediately discovered.
The default setting is 0. Once set, this implicit wait takes effect throughout the life cycle of the Webdriver object instance. Once.
1 Packagecom.test.elementwait;2 3 ImportJava.text.SimpleDateFormat;4 ImportJava.util.Calendar;5 ImportJava.util.concurrent.TimeUnit;6 7 Importorg.openqa.selenium.By;8 Importorg.openqa.selenium.NoSuchElementException;9 ImportOrg.openqa.selenium.WebDriver;Ten ImportOrg.openqa.selenium.firefox.FirefoxDriver; One Importorg.openqa.selenium.support.ui.WebDriverWait; A - Public classimplicitwait { - the Public Static voidMain (string[] args) { -Webdriver Driver =Newfirefoxdriver (); - driver.manage (). Timeouts (). implicitlywait (timeunit.seconds); -Driver.get ("http://www.baidu.com"); + driver.manage (). window (). Maximize (); - + Try { ASimpleDateFormat format =NewSimpleDateFormat ("Hh-mm-ss-sss"); atString time =Format.format (Calendar.getinstance (). GetTime ()); -System.out.println ("Start time:" +Time ); - -Driver.findelement (By.id ("Kw22")). SendKeys ("Selenium")); - -}Catch(nosuchelementexception e) { inSYSTEM.OUT.PRINTLN ("no element Found"); - e.printstacktrace (); to}finally { +SimpleDateFormat FORMAT2 =NewSimpleDateFormat ("Hh-mm-ss-sss"); -String time2 =Format2.format (Calendar.getinstance (). GetTime ()); theSystem.out.println ("End of Time:" +time2); * driver.quit (); $ }Panax Notoginseng - } the +}
Execution Result:
1 start time: 23-12-26-775 2 no element found3 org.openqa.selenium.NoSuchElementException:Unable to locate element: {"method": "id", "selector": "Kw22"}4 Command duration or timeout:10.46 seconds5 for documentation on this error, please visit:http://seleniumhq.org/exceptions/no_such_element.html6 Build info:version: ' 2.53.0 ', Revision: ' 35ae25b ', Time: ' 2016-03-15 16:57:40 '7 8 Driver Info:org.openqa.selenium.firefox.FirefoxDriver9 capabilities [{applicationcacheenabled=true, Rotatable=false, Handlesalerts=true, Databaseenabled=true, version =45.2.0, Platform=windows, Nativeevents=false, Acceptsslcerts=true, Webstorageenabled=true, locationContextEnabled= True, Browsername=firefox, Takesscreenshot=true, Javascriptenabled=true, cssselectorsenabled=true}]Ten Session id:dda0673c-da3d-4173-a904-d17148a3e26e One * * Element info: {using=id, value=kw22} A At Sun.reflect.NativeConstructorAccessorImpl.newInstance0 (Native Method) - At sun.reflect.NativeConstructorAccessorImpl.newInstance (nativeconstructoraccessorimpl.java:62) - At sun.reflect.DelegatingConstructorAccessorImpl.newInstance (delegatingconstructoraccessorimpl.java:45) the At java.lang.reflect.Constructor.newInstance (constructor.java:408) - At org.openqa.selenium.remote.ErrorHandler.createThrowable (errorhandler.java:206) - At org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed (errorhandler.java:158) - At Org.openqa.selenium.remote.RemoteWebDriver.execute (remotewebdriver.java:678) + At org.openqa.selenium.remote.RemoteWebDriver.findElement (remotewebdriver.java:363) - At org.openqa.selenium.remote.RemoteWebDriver.findElementById (remotewebdriver.java:413) + At org.openqa.selenium.by$byid.findelement (by.java:218) A At org.openqa.selenium.remote.RemoteWebDriver.findElement (remotewebdriver.java:355) at At Com.test.elementwait.ImplicitWait.main (implicitwait.java:26) - time to end: 23-12-37-273
Selenium Test (Java)--implicit wait (10)