【问题标题】:How to locate the element using Selenium and Java如何使用 Selenium 和 Java 定位元素
【发布时间】:2019-08-24 20:55:10
【问题描述】:
<input class="chkbx-selection ng-pristine ng-untouched ng-valid" type="checkbox" value="test" id="isAgreeChkBox" ng-model="$root.isAgreement">

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

【问题讨论】:

  • 什么元素...?请编辑问题!
  • driver.findElement(By.Id("isAgreeChkBox"));

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


【解决方案1】:

所需元素是Angular 元素,因此您需要诱导WebDriverWait 以使所需元素可点击,您可以使用以下任一Locator Strategies

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

【讨论】:

    猜你喜欢
    • 2019-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-03
    • 1970-01-01
    相关资源
    最近更新 更多