Selenium无法找到此xpath,我尝试过每种方法都需要单击最后一个按钮,但我无法激活
我尝试了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();
}
我想单击此按钮并进行其余的测试。
答案 0 :(得分:0)
由于所需元素是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']")));
答案 1 :(得分:0)
您可以继续使用按钮名称。
WebElement deactivateBatchButton = driver.findElement(By.xpath("//*[text()='Deactivate']"));
deactivateBatchButton.click();