簡體   English   中英

Webdriver找不到元素

[英]Webdriver can't find the element

紐扣

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

我要單擊此按鈕並進行其余的測試。

由於所需元素是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']"))); 

您可以繼續使用按鈕名稱。

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

deactivateBatchButton.click();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM