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.

1  Packagecom.test.elementwait;2 3 Importorg.openqa.selenium.By;4 ImportOrg.openqa.selenium.WebDriver;5 ImportOrg.openqa.selenium.firefox.FirefoxDriver;6 Importorg.openqa.selenium.support.ui.ExpectedCondition;7 Importorg.openqa.selenium.support.ui.ExpectedConditions;8 Importorg.openqa.selenium.support.ui.WebDriverWait;9 Ten  Public classexplicitwait { One  A      Public Static voidMain (string[] args) { -Webdriver Driver =Newfirefoxdriver (); -Driver.get ("http://www.baidu.com"); the 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 A         NewWebdriverwait (driver,5). Until (Expectedconditions.presenceofelementlocated (By.xpath ("//*[@id = ' kw ']"))); at         //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 true -Expectedconditions.presenceofallelementslocatedby (By.xpath ("//*[@id = ' kw ']")); in         //whether the text in the element contains a tone string -Expectedconditions.texttobepresentinelementlocated (By.xpath ("//*[@id = ' kw ']"), "Baidu a Bit"); to         //whether the element contains a tone string in the Value property of the +Expectedconditions.texttobepresentinelementvalue (By.xpath ("//*[@id = ' kw ']"), "* * *"); -         //determine if the form can be cut past, you can cut the past and return true, otherwise put back false theExpectedconditions.frametobeavailableandswitchtoit (By.id ("* *")); *         //determines whether an element does not exist in the DOM or is not visible $Expectedconditions.invisibilityofelementlocated (By.xpath ("//*[@id = ' kw ']"));Panax Notoginseng         //determine if the element can be clicked -Expectedconditions.elementtobeclickable (By.xpath ("//*[@id = ' kw ']")); the         //wait for an element to be removed from the DOM +Expectedconditions.stalenessof (Driver.findelement (By.xpath ("//*[@id = ' kw ']"))); A         //determines whether an element is selected and is typically used in a drop-down list theExpectedconditions.elementtobeselected (By.xpath ("//*[@id = ' kw ']")); +         //determine whether an element is selected in accordance with the expected status -Expectedconditions.elementselectionstatetobe (By.xpath ("//*[@id = ' kw ']"),true); $         //determines whether the selected state of an element (positioned) matches the expected $Expectedconditions.elementselectionstatetobe (Driver.findelement (By.xpath ("//*[@id = ' kw ')"),false); -         //determine if alert is present in the page -         NewWebdriverwait (driver,5). Until (Expectedconditions.alertispresent ()); the         //--------------------Custom Judging Criteria----------------------------- -webdriverwait wait =NewWebdriverwait (Driver, 3);WuyiWait.until (NewExpectedcondition<boolean>() { the               PublicBoolean Apply (Webdriver webdriver) { -                  return!driver.findelement (By.xpath ("//*[@id = ' kw ')"). GetAttribute ("Class"). Contains ("X-form-invalid-field"); Wu                              } -                  }); About          $     } -  -}

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.