Reputation: 4100
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());
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.
Upvotes: 0
Views: 3181
Reputation: 4100
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));
I was inspired by one of the answers in this thread.
Upvotes: 1