Selenium Test (Java)--Explicit Wait (ix)

Source: Internet
Author: User
Tags xpath

Explicit waits can be judged by using selenium presets, or you can use a custom method.

 Packagecom.test.elementwait;Importorg.openqa.selenium.By;ImportOrg.openqa.selenium.WebDriver;ImportOrg.openqa.selenium.firefox.FirefoxDriver;Importorg.openqa.selenium.support.ui.ExpectedCondition;Importorg.openqa.selenium.support.ui.ExpectedConditions;Importorg.openqa.selenium.support.ui.WebDriverWait; Public classexplicitwait { Public Static voidMain (string[] args) {Webdriver driver=NewFirefoxdriver (); Driver.get ("Http://www.baidu.com");        Driver.manage (). window (). Maximize (); //title is not "Baidu a bit, you will know"        NewWebdriverwait (driver,5). Until (Expectedconditions.titleis ("Baidu, you Know")); //title is not included "Baidu a Bit"        NewWebdriverwait (driver,5). Until (Expectedconditions.titlecontains ("Baidu a Bit"))); //determining whether the element is loaded in the DOM does not necessarily mean that the element is visible        NewWebdriverwait (driver,5). Until (Expectedconditions.presenceofelementlocated (By.xpath ("//*[@id = ' kw ']"))); //determines whether the element (after positioning) is visible        NewWebdriverwait (driver,5). Until (Expectedconditions.visibilityof (driver.findelement ("by.xpath @id = ' kw ']")))); //determines whether the element is visible (not hidden, and the width and height of the element are not equal to 0)        NewWebdriverwait (driver,5). Until (Expectedconditions.visibilityofelementlocated (By.xpath ("//*[@id = ' kw ']"))); //as long as there is one is trueExpectedconditions.presenceofallelementslocatedby (By.xpath ("//*[@id = ' kw ']")); //whether the text in the element contains a tone stringExpectedconditions.texttobepresentinelementlocated (By.xpath ("//*[@id = ' kw ']"), "Baidu a Bit"); //whether the element contains a tone string in the Value property of theExpectedconditions.texttobepresentinelementvalue (By.xpath ("//*[@id = ' kw ']"), "* * *"); //determine if the form can be cut past, you can cut the past and return true, otherwise put back falseExpectedconditions.frametobeavailableandswitchtoit (By.id ("* *")); //determines whether an element does not exist in the DOM or is not visibleExpectedconditions.invisibilityofelementlocated (By.xpath ("//*[@id = ' kw ']")); //determine if the element can be clickedExpectedconditions.elementtobeclickable (By.xpath ("//*[@id = ' kw ']")); //wait for an element to be removed from the DOMExpectedconditions.stalenessof (Driver.findelement (By.xpath ("//*[@id = ' kw ']"))); //determines whether an element is selected and is typically used in a drop-down listExpectedconditions.elementtobeselected (By.xpath ("//*[@id = ' kw ']")); //determine whether an element is selected in accordance with the expected statusExpectedconditions.elementselectionstatetobe (By.xpath ("//*[@id = ' kw ']"),true); //determines whether the selected state of an element (positioned) matches the expectedExpectedconditions.elementselectionstatetobe (Driver.findelement (By.xpath ("//*[@id = ' kw ')"),false); //determine if alert is present in the page        NewWebdriverwait (driver,5). Until (Expectedconditions.alertispresent ()); //--------------------Custom Judging criteria-----------------------------webdriverwait wait =NewWebdriverwait (Driver, 3); Wait.until (NewExpectedcondition<boolean>() {              PublicBoolean Apply (webdriver driver) {return!driver.findelement (By.xpath ("//*[@id = ' kw ')"). GetAttribute ("Class"). Contains ("X-form-invalid-field");            }                 }); }}

Note:

1. In addition to the above, selenium also offers a number of pre-determined methods.

2. These methods of judgment throw an exception when the time limit is exceeded.

Selenium Test (Java)--Explicit Wait (ix)

Related Article

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.