1. Using the Java Sleep
Try { Thread.Sleep (+); Catch (interruptedexception e) { // TODO auto-generated catch block E.printstacktrace (); }
2. Using Selenium's webdriverwait, show wait
Public voidF1 () {Dr.get ("Http://www.baidu.com"); webdriverwait wait=NewWebdriverwait (dr,10); Wait.until (NewExpectedcondition<webelement>() {@Override Publicwebelement Apply (Webdriver arg0) {//TODO auto-generated Method Stub returnArg0.findelement (By.id ("kw")); }}). SendKeys ("Test"); Wait.until (NewExpectedcondition<boolean>() {@Override PublicBoolean Apply (Webdriver arg0) {//TODO auto-generated Method Stub returnArg0.findelement (By.id ("2") . isdisplayed (); } }); }
Constructs the method, displays waits for up to 10 seconds, until appears the following the Apply method (overrides) The element object, the first overrides the Apply method returns the element objects, the second overrides the Apply method returns the boolean,10 second to appear, then runs down, after 10 seconds still does not appear, throws the exception
3. Using the selenium implicit wait, the global
Dr.manage (). Timeouts (). implicitlywait (Timeunit.seconds);
In the project, feel the third way, the most used is the first and the second, recommended the second kind, intelligent waiting
Selenium several ways to wait