Appium/Selenium-断言未显示声明为字段的元素 [英] Appium/Selenium - assert that element declared as field is NOT displayed

查看:199
本文介绍了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?

我不想在代码中多次定义按条件的东西,因此使用属性非常方便.

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));

查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆