public class LoginPage {
WebDriver driver;
@FindBy(xpath = "//input[contains(@class,'oxd-input') and @name='username']")
private WebElement userName;
@FindBy(xpath = "//input[contains(@class,'oxd-input') and @name='password']")
private WebElement password;
@FindBy(xpath = "//input[contains(@class,'oxd-button') and @type='submit']")
private WebElement loginButton;
public LoginPage(WebDriver driver) {
this.driver = driver;
PageFactory.initElements(driver, this);
}
public void enterUserName(String userNameValue) {
userName.sendKeys(userNameValue);
}
public void enterPassword(String pwd) {
password.sendKeys(pwd);
}
public void clickLoginBtn() {
loginButton.click();
}
}
@When("User logins in with correct credentials")
public void user_logins_in_with_correct_credentials() {
SeleniumManager.getInstance().getDriverPath("chromedriver");
driver = new ChromeDriver();
driver.get("https://opensource-demo.orangehrmlive.com/web/index.php/auth/login");
driver.manage().window().maximize();
login = new LoginPage(driver);
login.enterUserName("Admin");
login.enterPassword("admin123");
login.clickLoginBtn();
}
Error Message:
org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//input[contains(@class,'oxd-input') and @name='username']"}