我需要从Excel工作表导入数据并提供它以导航到网站。您可以建议我如何使用selenium webdriver实现它。
答案 0 :(得分:0)
在这里你需要使用apache POI库。 apache-poi
Hope this will help you
String fileName1 = "D://TestData//MyDataSheet1.xlsx",
FileInputStream fis1 = new FileInputStream(new File(fileName1));
XSSFWorkbook workbook1 = new XSSFWorkbook (fis1);
XSSFSheet sheet1 = workbook1.getSheetAt(0);
Iterator ite1 = sheet1.rowIterator();
while(ite1.hasNext()){
Row row = (Row) ite1.next();
Iterator<Cell> cite = row.cellIterator();
while(cite.hasNext()){
Cell a1 = cite.next(),
a2 = cite.next();
driver.findElement(By.id("emailAddress")).clear();
driver.findElement(By.id("emailAddress")).sendKeys(a1.toString().trim());
driver.findElement(By.id("password")).clear();
driver.findElement(By.id("password")).sendKeys(a2.toString().trim());
}
}
答案 1 :(得分:0)
我使用JXL api从excel中提取数据。您可以使用JXL或POI,您可以使用它们。以下是提取数据的代码:
String FilePath = "path to your excel file";
FileInputStream fis = new FileInputStream (FilePath);
Workbook workbook = Workbook.getWorkbook(fis);
Sheet sheet = workbook.getSheet("sheetname");
String URL = sheet.getCell(row,col).getContents();
You can now use the above string URL in your code.
driver.navigate.To(URL) or
driver.get(URL);
I hope this helps.