java - 如何在浏览器中从excel中一一读取和运行多个URL
问题描述
请建议我一些代码,用于从 selenium 中的 excel 文件中读取和执行大约 300 个 URL。
我做了这样的事情:
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver", "C:\\Users\\Jatin\\Downloads\\chromedriver_win32\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://example.com/");
List<WebElement> getLinks = driver.findElements(By.tagName("a"));
// to get the list of urls from the website
System.out.println(getLinks.size());
//fetch data from excel
try {
File excel = new File("C:\\Users\\Jatin\\Documents\\Output.xlsx");
FileInputStream fis = new FileInputStream(excel);
XSSFWorkbook book = new XSSFWorkbook(fis);
XSSFSheet sheet = book.getSheetAt(0);
Iterator<Row> itr = sheet.iterator();
// Iterating over Excel file in Java
while (itr.hasNext()) {
Row row = itr.next();
Iterator<Cell> cellIterator = row.cellIterator();
while (cellIterator.hasNext()) {
Cell cell = cellIterator.next();
switch (cell.getCellType()) {
case STRING:
System.out.print(cell.getStringCellValue() + "\t");
break;
case NUMERIC:
System.out.print(cell.getNumericCellValue() + "\t");
break;
case BOOLEAN:
System.out.print(cell.getBooleanCellValue() + "\t");
break;
default:
}
}
System.out.println("");}
}catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
解决方案
推荐阅读
- php - 使用 DOMXPath 和 DomDocument 检查网站是否使用有效的 AMP 结构
- python - 修改加权图
- akka-http - akka http Route orElse
- c - 如何声明一个全局结构数组并在不同的函数中使用它?
- javascript - 如何通过 Ember 中的脚本标签供应第 3 方 js 库?
- bash - Ansible,复制脚本,然后在远程机器上执行
- html - 仅使用 CSS 重构响应式设计中的部分
- file-upload - TinyMCE5 不通过拖放上传图像
- mysql - 创建餐厅菜单我应该使用 has_many through 还是 habtm 关联?
- awk - awk 先于模式匹配与找到的结果数