I have been practicing using POM design approach (with Data Driven & testNg framework) for Selenium;
I recently got to see a selenium automation developer using POM with neither @FindBy nor PageFactory in the script
What I didn't understand using 'By' in the selenium script as follows:
By element_name = By.id("String");
'By' is an abstract class (as mentioned in selenium -- java api documentation), and the methods such id, classname, name, xpath and etc are static methods;
Based on these facts, how is the abstract class and static methods are directly implemented?
Below is the code I am talking about.
public TrialLoginPage(WebDriver driver, Properties prop) {
super(driver, prop);
}
By name = By.name("username");
By password = By.name("password");
By submit = By.xpath("//input[@type='submit']");
public String getTitle() {
String title = driver.getTitle();
return title;
}
public WebElement setUserName() {
WebElement element = driver.findElement(name);
return element;
}
public WebElement setPassword() {
WebElement element = driver.findElement(password);
return element;
}
public WebElement setSubmit() {
WebElement login = driver.findElement(submit);
return login;
}
public String driverStatus() {
String str = driver.toString();
return str;
}
}