HTML: IDs

Last updated on:

There is few different ways to locate element on the page using ID.
First is most simple one:

public class HomePageContainer {

WebDriver driver = new FirefoxDriver();

public static void navigateToLoginPage(){
    driver.findElemnt(By.id("username")).sendKeys("myName");
   }
}

But when it comes to developing test automation framework I would rather use next two, just because it is giving you flexibility and proper lair of abstraction:

public class HomePageContainer {
    @FindBy(how = How.ID, using = "username")
    public WebElement userName;

public static void enterUserName(){
    userName.sendKeys("myName");
   }
}
public class HomePageContainer {
    @FindBy(id = "username")
    public WebElement userName;

public static void enterUserName(){
    userName.sendKeys("myName");
   }
}
View Comments

Leave a Comment

Use markdown or basic HTML and be nice.