Selenium several ways to wait

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.