Я хочу создать метод java, который может проверять, существует ли фактический webelement селена.
Важно, что мне нужно создать метод, который бы получал Webelement в качестве параметра, а не By илиИдентификатор строкиИ я хочу избежать решения try-catch, которое возвращало бы false, если возникнет исключение NoSuchElementException.
public boolean isElementExists(WebElement element) {
//TODO Implement...
}
Пример:
foo.html
<!DOCTYPE html>
<html>
<body>
<button id="button1" type="button">First button</button>
</body>
</html>
FooPage.java
public class FooPage {
@FindBy(how = How.ID, using = "button1")
public WebElement fistButton;
//Missing button
@FindBy(how = How.ID, using = "button2")
public WebElement secondButton;
}
FooPageTest.java
public class FooPageTest {
public void test(FooPage page) {
page.firstButton.click(); // OK
page.secondButton.click(); // NoSuchElementException
//So I need to check if element exists in this class.
//I can access here to the FooPage, the webelement to check, and to the driver.
}
}