I am trying to use By in selenium as a String to get my element but it is giving me the error "'id(java.lang.String)' in 'org.openqa.selenium.By' cannot be applied to '(org.openqa.selenium.By)'"
Please assist me Here is my code:
package adta;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
public class LoginPage extends BasePage {
public LoginPage(WebDriver driver) {
super(driver);
}
public By getUserNameLocator(){
return By.id("user-name");
}
public void open(){
driver.get("https://www.saucedemo.com/");
}
public boolean isLoaded(){
return wait.until(ExpectedConditions.visibilityOfElementLocated(By.id(getUserNameLocator()))).isDisplayed();
}
public void login(String username, String password) {
driver.findElement(By.id(getUserNameLocator())).sendKeys(username);
driver.findElement(By.id("password")).sendKeys(password);
driver.findElement(By.id("login-button")).click();
}
}
I have tried to search for answers online but no luck