我有两个类,一个运行单击按钮等的方法。在页面上,有一个被禁用的按钮,我有一个WebDriverWait,通过检查" disabled“属性是否已经从html元素中删除,等待它再次被启用。然而,当我运行测试时,我得到了一个nullPointerException。我想我知道它是从哪里来的,但在尝试解决它的方法时遇到了问题。
以下是运行get以执行操作的方法:
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");
}
在这方面的任何帮助都将不胜感激!
https://stackoverflow.com/questions/38263603
复制相似问题