我试图从excel文件中读取数据,但控制台提供了系统无法找到指定路径的异常。但我已经给出了正确的路径,文件也是可访问的。请帮我解决这个问题。
WebDriver driver = new FirefoxDriver();
driver.get("someurl");
Workbook book = Workbook.getWorkbook(new File("E:\\TestDataforSelenium1.xls"));
Sheet sh= book.getSheet("TestData");
for(int i=0; i<sh.getRows(); i++)
{
String username=sh.getCell(0, i).getContents();
String password=sh.getCell(1, i).getContents();
driver.findElement(ByName.name("uid")).sendKeys(username);
driver.findElement(ByName.name("password")).sendKeys(password);
driver.findElement(ByName.name("btnLogin")).click();
try
{
Alert alt=driver.switchTo().alert();
String alerttext=alt.getText();
System.out.println(alerttext);
if(alerttext.equalsIgnoreCase("User or Password is not valid"))
{
alt.accept();
System.out.println("test case pass with invalid credential and valid error message");
}
else
System.out.println("test case pass with invalid credential");
}
catch (NoAlertPresentException Ex)
{
String url ="http://www.demo.guru99.com/V4/manager/Managerhomepage.php";
if (url.equalsIgnoreCase("http://www.demo.guru99.com/V4/manager/Managerhomepage.php"))
System.out.println("Verify that user is successfully able to login.");
else
System.out.println("Verify that user is not able to log into the application.");
}
}