Appium/Selenium - 断言声明为字段的元素不显示 [英] Appium/Selenium - assert that element declared as field is NOT displayed
本文介绍了Appium/Selenium - 断言声明为字段的元素不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我以下列方式将按钮声明为字段:
I declare a button as field in following fashion:
@AndroidFindBy(name = "Schedule")
private WebElement calendarButton;
... 后来我确保它没有显示,因为应用程序处于某种特殊模式.
... and later I make sure it's NOT displayed because the app is in some special mode.
Assert.assertFalse(this.calendarButton.isDisplayed());
它给了我 org.openqa.selenium.NoSuchElementException,但是测试失败了.任何想法我怎么能做出这样的断言?
It gives me org.openqa.selenium.NoSuchElementException, but the test is failed. Any ideas how can I make such assertion?
我不想在代码中多次定义 By 条件,所以使用属性很方便.
The thing I don't want to define By condition a few times in the code, so using property is handy.
推荐答案
经过一番思考,我想出了以下解决方案:
After some thinking I came up with following solution:
public static boolean elementIsPresent(AndroidElement element) {
try {
element.isDisplayed();
} catch (org.openqa.selenium.NoSuchElementException e) {
return false;
}
return true;
}
我以下列方式使用此方法:
I use this method in following way:
Assert.assertFalse(elementIsPresent(this.calendarButton));
我的灵感来自 这个线程.
这篇关于Appium/Selenium - 断言声明为字段的元素不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文