Can anyone explain me about Annotation @FindBy
in WebDriver
?
Where and why it is used?
It's to assist with the construction of locators when using the Page Factory to support your Page Objects
However I'm discovering that I find it more useful to store your locators as By objects rather than WebElements as they are more flexible and you tend to avoid running into the StaleElementException.
By myLocator = By.id("idOfYourElement")
instead of
@FindBy(id = "idOfYourElement")
WebElement myLocator;
This way you can also use your locators when asserting the absence of an element or use it in the ExpectedConditions helpers.