我按照以下方式将按钮声明为字段:
@AndroidFindBy(name = "Schedule")
private WebElement calendarButton;
...后来我确保它不会显示,因为应用程序处于某种特殊模式。
Assert.assertFalse(this.calendarButton.isDisplayed());
它给了我org.openqa.selenium.NoSuchElementException,但测试失败。我有什么想法可以做出这样的断言吗?
我不想在代码中多次定义“按条件”,因此使用属性很方便。
最佳答案
经过一番思考,我想出了以下解决方案:
public static boolean elementIsPresent(AndroidElement element) {
try {
element.isDisplayed();
} catch (org.openqa.selenium.NoSuchElementException e) {
return false;
}
return true;
}
我按以下方式使用此方法:
Assert.assertFalse(elementIsPresent(this.calendarButton));
我受到this thread中的一个答案的启发。 .
关于java - Appium/Selenium - 断言声明为字段的元素不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33387189/