我正在尝试使用所有有效和无效的输入验证登录部分 .
这是我试过的代码:
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();
}
我想在每次登录失败时显示错误消息,这很正常 . 但当 login is successful 具有有效输入时,它显示:
“org.openqa.selenium.NoSuchElementException:没有这样的元素:无法找到元素:{”method“:”xpath“,”selector“:”// * [@ id ='eError']“}”
因为错误消息未成功登录 .
你能帮我解决一下这个问题 .