I have gone through the many blogs and sites to get more information about POM (Page Object Model). However, some of blogs gives examples using @FindBy with PageFactory for getting the web element and some of blogs has create the method with written by WebElement and finding element using findElement() methods as given below:
1. @FindBy(id="clickhere")
WebElement linkClickHere;
public classconstructor(WebDriver driver){
return PageFactory.initElements(driver, classname.class);
}
2. public static WebElement lnk_MyAccount(WebDriver driver){
return driver.findElement(By.id("clickhere"));
}
I understand that, using factory we get all the element of web page before executing the script and from second point, it looks for element at the time of script execution, correct me if I am wrong.
Now, which one we should use? Which is the best among this? Is there any difference between this two? What are the advantage and disadvantage for this two?
I would appreciate your inputs....