【发布时间】:2016-07-08 09:47:05
【问题描述】:
我有两个类,一个运行单击按钮等的方法。在页面上,有一个按钮被禁用,我有一个 WebDriverWait 通过检查属性“禁用”来等待它再次启用" 已从 html 元素中删除。但是,当我运行测试时,我得到一个 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");
}
对此的任何帮助将不胜感激!
【问题讨论】:
标签: java selenium selenium-webdriver testng