需要有关如何继续以下方案的输入:
我们可以在带有java的webdriver中执行此操作吗?
答案 0 :(得分:0)
使用POI罐子 使用getXLcellValue函数获取excel中的值 使用setXLCellValue函数在excel中设置值
参数: -
rowNum和cellNum - >数据所在的行号和列号 本
public String getXLcellValue(String xlpath, String sheetName, int rowNum, int cellNum)
{
try{
FileInputStream fis=new FileInputStream(xlpath);
Workbook wb=WorkbookFactory.create(fis);
Log.info("Get the value from the cell(getXLcellValue)");
return wb.getSheet(sheetName).getRow(rowNum).getCell(cellNum).getStringCellValue();
}
catch(Exception ex)
{
Log.info("Error in getXLcellValue ="+ ex.getMessage());
}
return "";
}
//set the value of the cell present in specific sheet
void setXLCellValue(String xlpath,String sheetName,int rowNum,int cellNum, String input)
{
try{
FileInputStream fis=new FileInputStream(xlpath);
Workbook wb=WorkbookFactory.create(fis);
wb.getSheet(sheetName).getRow(rowNum).createCell(cellNum).setCellValue(input);
FileOutputStream fos=new FileOutputStream(xlpath);
wb.write(fos);
fos.close();
Log.info("Set the value in cell(setXLCellValue)");
}
catch(Exception ex)
{
Log.info("Error in setXLCellValue ="+ ex.getMessage());
}
}
使用第一个函数从Excel中检索数据。 其次根据您的需要在网络上进行操作 第三个使用set函数在Excel中设置值。
您可以在网上搜索类似的内容
Actions builder = new Actions(driver);
Action select= builder
.keyDown(Keys.CONTROL)
.sendKeys("f")
.keyUp(Keys.CONTROL)
.sendKeys("ss")
.build();
select.perform();
OR使用机器人类(不推荐)
driver.get("https://www.google.co.in/");
driver.findElement(By.xpath("//input[@name='btnK']")).sendKeys(Keys.chord(Keys.CONTROL, "f"));
try{
Robot robot= new Robot();
robot.keyPress(KeyEvent.VK_W);
robot.keyRelease(KeyEvent.VK_W);
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
}
catch(Exception ex)
{
}
希望它会对你有所帮助:)。