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.
Packagecom.test.elementwait;ImportJava.text.SimpleDateFormat;ImportJava.util.Calendar;ImportJava.util.concurrent.TimeUnit;Importorg.openqa.selenium.By;Importorg.openqa.selenium.NoSuchElementException;ImportOrg.openqa.selenium.WebDriver;ImportOrg.openqa.selenium.firefox.FirefoxDriver;Importorg.openqa.selenium.support.ui.WebDriverWait; Public classimplicitwait { Public Static voidMain (string[] args) {Webdriver driver=NewFirefoxdriver (); Driver.manage (). Timeouts (). Implicitlywait (10, Timeunit.seconds); Driver.get ("Http://www.baidu.com"); Driver.manage (). window (). Maximize (); Try{SimpleDateFormat format=NewSimpleDateFormat ("Hh-mm-ss-sss"); String Time=Format.format (Calendar.getinstance (). GetTime ()); System.out.println ("Start time:" +Time ); Driver.findelement (By.id ("Kw22")). SendKeys ("Selenium")); } Catch(nosuchelementexception e) {System.out.println ("No element Found"); E.printstacktrace (); } finally{SimpleDateFormat format2=NewSimpleDateFormat ("Hh-mm-ss-sss"); String time2=Format2.format (Calendar.getinstance (). GetTime ()); System.out.println ("End of Time:" +time2); Driver.quit (); } }}
Execution Result:
Time to start: 23-12-26-775no elements found org.openqa.selenium.NoSuchElementException:Unable to locate element: {"Method": "id", "selector": "Kw22"}command Duration or timeout:10.46secondsfor Documentation on ThisError, please visit:http://seleniumhq.org/exceptions/no_such_element.htmlBuild info:version: ' 2.53.0 ', Revision: ' 35ae25b ', Time: ' 2016-03-15 16:57:40 ' 8Driver info:org.openqa.selenium.firefox.FirefoxDriverCapabilities [{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}]session id:dda0673c-da3d-4173-a904-d17148a3e26eElement Info: {using=id, value=Kw22} at Sun.reflect.NativeConstructorAccessorImpl.newInstance0 (Native Method) at Sun.reflect.NativeConstructor Accessorimpl.newinstance (Nativeconstructoraccessorimpl.java:62) at Sun.reflect.DelegatingConstructorAccessorImpl.newInstance (Delegatingconstructoraccessorimpl.java:45) 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:37]) 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) at Org.openqa.selenium.remote.RemoteWebDriver.findElement (Remotewebdriver.java:355) at Com.test.elementwait.ImplicitWait.main (Implicitwait.java:26) End of time:23-12-37-273
Selenium Test (Java)--implicit wait (10)