【问题标题】:Webdriver can't find the elementWebdriver 找不到元素
【发布时间】:2019-01-12 22:09:30
【问题描述】:

Selenium 找不到这个 xpath 我尝试了所有需要单击最后一个按钮的方法 Deactivate 但我找不到

我试过 xpath,cssSelectors,

 @When("^I click deactivate button$")
public void iClickDeactivateButton(){
    WebElement deactivateBatchButton = driver.findElement(By.xpath("//BUTTON[@_ngcontent-c14=''][text()='Deactivate'][text()='Deactivate']/self::BUTTONclass='deactivate']"));
    deactivateBatchButton.click();
}

我想点击这个按钮并进行其余的测试。

【问题讨论】:

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


    【解决方案1】:

    由于所需的元素是 Angular 元素并且要找到它,您必须诱导 WebDriverWait 并且您可以使用以下任一解决方案:

    • cssSelector:

      WebElement deactivateBatchButton = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("button.deactivate.xh-highlight")));
      
    • xpath:

      WebElement deactivateBatchButton = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@class='deactivate xh-highlight' and text()='Deactivate']")));
      

    【讨论】:

      【解决方案2】:

      您可以继续使用按钮名称。

          WebElement deactivateBatchButton = driver.findElement(By.xpath("//*[text()='Deactivate']"));
      
      deactivateBatchButton.click();
      

      【讨论】:

        猜你喜欢
        • 2016-03-20
        • 1970-01-01
        • 1970-01-01
        • 2022-11-11
        • 2016-09-07
        • 2018-09-19
        • 2017-10-24
        • 1970-01-01
        相关资源
        最近更新 更多