使用 Selenium,我编写了以下代码来从 Excel 工作表中读取数据,并将电子邮件和密码键入 Facebook 的登录页面。错误是使用 try/catch 的未处理表达式。我该如何解决这个问题?
package Excelpack;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;
import org.testng.annotations.DataProvider;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
public class ClassTwo {
WebDriver driver;
String username;
String password;
@Test(dataProvider="testdata")
public void testFireFox(String uname, String password1){
driver.findElement(By.id("email")).clear();
driver.findElement(By.id("email")).sendKeys(uname);
driver.findElement(By.id("pass")).clear();
driver.findElement(By.id("pass")).sendKeys(password1);
}
@DataProvider(name="testdata")
public Object[][] TestDataFeed1()
{
FileInputStream fis=new FileInputStream("D:\\book3.xlsx");
XSSFWorkbook wb=new XSSFWorkbook(fis);
XSSFSheet sh1= wb.getSheetAt(0);
int numrow = sh1.getLastRowNum()-sh1.getFirstRowNum();
int colnum =sh1.getRow(1).getLastCellNum()+1;
Object [][] facebookdata=new Object[numrow][colnum];
for(int i=0;i<numrow;i++)
{
facebookdata[i][0]=sh1.getRow(0).getCell(i).getStringCellValue();
facebookdata[i][1]=sh1.getRow(1).getCell(i).getStringCellValue();
}
return facebookdata;
}
@BeforeTest
public void Setup(){
driver=new FirefoxDriver();
driver.manage().window().maximize();
driver.get("https://www.facebook.com/");
}
}