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