![](/img/trans.png)
[英]how to check if a button is clickable in java,selenium webdriver.ps:check if clickable not wait untill it is clickable
[英]How to check if the button is clickable using selenium webdriver
我正在嘗試查找按鈕元素是否可單擊,而我無法使用Selenium Webdriver進行成功驗證。
這是我的代碼,以驗證元素是否可點擊
boolean installAFile;
String classValues = driver.findElement(by.XPATH("//button[contains(., 'Install a new file')]")).getAttribute("class");
installAFIle = classValues.contains("iconbutton-button--clickable");
return installAFIle;
這是HTML
<div>
<!-- react-text: 406 -->
test message 1
<!-- /react-text -->
<div class="iconbutton">
<button class="iconbutton-button iconbutton-button--clickable" type="button"
tabindex="0">
<div class="iconbutton-button-label">Install a new file</div>
</button>
</div>
<!-- react-text: 410 -->
under File > Install.
<!-- /react-text -->
</div>
我一直收到以下驗證消息: 沒有這樣的元素:無法找到元素:{“ method”:“ xpath”,“ selector”:“ // button [contains(。,'Install a new file')]”“}
只需編寫以下方法,並在需要檢查元素是否可單擊時調用它。 還傳遞必需的參數。
public static boolean isClickable(WebElement el, WebDriver driver)
{
try{
WebDriverWait wait = new WebDriverWait(driver, 6);
wait.until(ExpectedConditions.elementToBeClickable(el));
return true;
}
catch (Exception e){
return false;
}
}
/html/body/div/div/button/div
要么
//button/div
要么
//div[contains(@class,'iconbutton-button-label')]
要么
//*[contains(text(), 'Install a new file')]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.