Selenium webdriver 我试图从excel文件中读取用户名和密码,但它在sendkeys方法中显示错误
公共静态void main(字符串[]args)引发InvalidFormatException,IOException{Selenium webdriver 我试图从excel文件中读取用户名和密码,但它在sendkeys方法中显示错误,selenium-webdriver,Selenium Webdriver,公共静态void main(字符串[]args)引发InvalidFormatException,IOException{ WebDriver wd=new FirefoxDriver(); wd.navigate().to("http://www.gmail.com"); Object[][] Arr=new Object[4][2]; InputStream fi=new FileInputStream("C:\\Users\\harini.b\\Desktop\\excel
WebDriver wd=new FirefoxDriver();
wd.navigate().to("http://www.gmail.com");
Object[][] Arr=new Object[4][2];
InputStream fi=new FileInputStream("C:\\Users\\harini.b\\Desktop\\excel.xlsx");
Workbook wb=WorkbookFactory.create(fi);
Sheet s=wb.getSheetAt(0);
int row=s.getLastRowNum();
System.out.println("no of rows: "+row);
for(int i=0;i<row;i++)
{
Row r=s.getRow(i+1);
int col=r.getLastCellNum();
for(int j=0;j<col;j++){
Cell c=r.getCell(j);
if(c.getCellType()==c.CELL_TYPE_STRING){
Arr[i][j]=c.getStringCellValue();
}else if(c.getCellType()==c.CELL_TYPE_NUMERIC){
Arr[i][j]=c.getNumericCellValue();
}
wd.findElement(By.id("Email")).sendKeys(Arr[i][0]);
wd.findElement(By.id("Passwd")).sendKeys(Arr[0][j]);
}
}
WebDriver wd=newfirefoxdriver();
wd.navigate()到(“http://www.gmail.com");
Object[]Arr=新对象[4][2];
InputStream fi=新文件InputStream(“C:\\Users\\harini.b\\Desktop\\excel.xlsx”);
工作簿wb=WorkbookFactory.create(fi);
表s=wb.getSheetAt(0);
int row=s.getLastRowNum();
System.out.println(“行数:”+行);
对于(inti=0;i您的数组'Arr'是一个'java.lang.Object'数组
Object[]Arr=新对象[4][2];
方法“sendKeys”需要charSequence。编译器必须告诉您类似“类型WebElement中的方法sendKeys(charSequence…)不适用于参数(对象)”
确保电子表格仅包含字符串值,并将数组声明为“java.lang.string”