what are the advantages of page factory in selenium code example

Example 1: advantages of page factory in selenium

/*** 
* Constructor 
* @param driver an instance of WebDriver 
*/
public int TimeoutValue = 30;
public SearchResultsPage(Webdriver driver) { 
    PageFactory.initElements(new AjaxElementLocatorFactory(driver, TimeoutValue), this);
}

Example 2: advantages of page factory in selenium

public class BasePage {

private By username = By.id("username");
private By password = By.id("password");
private By loginBtn = By.name("loginbtn");

  public void userLogin(String userName, String password) {
        driver.findElement(username).sendKeys("testuser");
        driver.findElement(password).sendKeys("testpassword");
        driver.findElement(loginBtn).click();
  }
}

Tags:

Misc Example