I'm writing tests for a system that shows a Popup on the first login but doesn't on the subsequent logins.
Currently my code is something like this:
PopupPage
class PopupPage extends BasePage {
@FindById(id="closeBtn")
private WebElement closeButton;
public boolean isDisplayed(){
//Throws an error when the popup isn't displayed because the popup isn't in the DOM.
return closeButton.isDisplayed();
}
}
This is very similar to this question, but I don't want to repeat the selector that is already present in the FindById notation.
So how do I assert that the element is on page or not ? (Ideally I would like to have some method coming from the WebElement like closeButton.isStale()
or something like this.
NoSuchElementException
when trying to check the textdriver.findElements(By.id("closeBtn")).size() == 0
but then I would be duplicating the selector.