如何使用Selenium和Java定位元素

时间:2019-04-03 10:45:24

标签: java selenium-webdriver xpath css-selectors selenide

<input class="chkbx-selection ng-pristine ng-untouched ng-valid" type="checkbox" value="test" id="isAgreeChkBox" ng-model="$root.isAgreement">

请帮助我在这里找到什么是xpath / css选择器?我需要使用硒化物中的定位器来定位

1 个答案:

答案 0 :(得分:0)

所需元素是Angular元素,因此您需要诱使 WebDriverWait 使所需元素可点击,并且您可以使用以下任一{ {3}}:

  • cssSelector

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("input.chkbx-selection.ng-pristine.ng-untouched.ng-valid#isAgreeChkBox[value='test']"))).click();
    
  • xpath

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@class='chkbx-selection ng-pristine ng-untouched ng-valid' and @id='isAgreeChkBox'][@value='test']"))).click();