繁体   English   中英

如何使用 Selenium 和 Java 定位元素

[英]How to locate the element using Selenium and Java

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

请帮我找到这里的 xpath/css 选择器是什么? 我需要使用 selenide 中的定位器来定位它

所需元素是一个Angular元素,因此您需要引入WebDriverWait以使所需元素可点击,您可以使用以下任一定位器策略

  • 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();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM