I want to use "FindBy" annotation to search web element objects, but when I use it, it returns null. This is what am I using:
class TestPage {
@FindBy(xpath="//*[@id=\"mat-input-0\"]")
public static WebElement identificationNumber
}
And this is how I call it:
TestPage.identificationNumber.sendKeys("TEST")
When I execute it, it prints an error saying: Cannot invoke method sendKeys() on null object.
I've tried also different method which works fine, but I don't understand why "FindBy" annotation does not work. This is working method:
def static setIdentificationNumber() {
WebElement identificationNumber = getWebDriver().findElement(By.xpath("//*[@id=\"mat-input-0\"]"))
def setText = identificationNumber.sendKeys("ABC")
}