1
我有兩個類,一個運行方法來點擊按鈕等。在頁面上,有一個按鈕被禁用,我有一個WebDriverWait等待它被再次啓用通過檢查屬性「disabled」已經從html元素中移除。但是,當我運行測試時,我得到一個nullPointerException。我想我知道它來自哪裏,但有一個問題試圖繞過它。使用WebDriverWait的NullPointerException布爾
這是一個運行去執行的操作方法:
public void methodThatRuns(WebDriver driver) throws InterruptedException {
properties.inputTxt(driver, "100");
sundries.waitEnabledButton(driver, properties.nextButton(driver));
properties.nextButton(driver).click();
}
這是從另一個類的waitEnabledButton方法,它調用等待:
public void waitEnabledButton(WebDriver driver, final WebElement btn) throws NullPointerException {
WebDriverWait wait = new WebDriverWait(driver, 10);
System.out.println("Starting the wait");
try {
wait.until(new ExpectedCondition<Boolean>(){
public Boolean apply(WebDriver driver) {
final String attribute = btn.getAttribute("disabled");
if (attribute.equals(null)) {
return true;
}
else {
return false;
}
}
});
} catch (StaleElementReferenceException e) {
System.out.println("The disabled attribute was destroyed successfully and the script can continue."); //using this as the attribute gets destroyed when the button is enabled which throws a staleElement exception
}
System.out.println("Wait is over");
}
任何幫助,在此將非常感謝!
這解決了我的問題!這麼簡單,但太精彩了!感謝那! – Moser