I am trying to validate a login section with all valid and invalid inputs.
here is the code i have tried:
public void login_Valid_Invalid_Combinations() throws BiffException, IOException, InterruptedException
{
String FilePath = "D://credentials.xls";
FileInputStream FIS = new FileInputStream(FilePath);
Workbook WB = Workbook.getWorkbook(FIS);
Sheet SH = WB.getSheet(0);
for(int row =0; row<= SH.getRows()-1; row++)
{
String userNAME = SH.getCell(0, row).getContents();
String passWORD = SH.getCell(1, row).getContents();
System.out.println("USERMANE : "+userNAME + " PASSWORD : "+passWORD);
driver.get("LOGIN PAGE URL");
driver.findElement(By.id("Email")).sendKeys(userNAME);
driver.findElement(By.id("Password")).sendKeys(passWORD);
driver.findElement(By.id("btnlogin")).click();
System.out.println(driver.findElement(By.xpath("//*[@id='eError']")).getText());
Thread.sleep(2000);
String URL = driver.getCurrentUrl();
System.out.println(URL);
if (URL.equals("URL AFTER SUCCESFULL LOGIN"))
{
System.out.println("Login Successfull");
}
else
{
System.out.println("Login Failed");
}
}
driver.close();
}
I want to show the error message each time login failed, which is working fine. But when login is successful with valid inputs, it's showing:
"org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id='eError']"}"
as the error message is not coming for successful login.
Can you please help me how to handle this.