Need inputs on how to proceed with the below scenario:
- Copy data from a excel file(For ex: email address)
- Search for it in a web page
- if find copy the corresponding data and paste it in another excel file
Can we do this in webdriver with java?
Need inputs on how to proceed with the below scenario:
Can we do this in webdriver with java?
Use POI jars Use getXLcellValue function to get the value in excel Use setXLCellValue function to set the value in excel
Parameters :-
rowNum and cellNum -> Row and column number where your data is present
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());
}
}
Use first function to retrive data from Excel. Secondly do opration on web as per your need Third use set function to set the value in Excel.
You can search on web something like that
Actions builder = new Actions(driver);
Action select= builder
.keyDown(Keys.CONTROL)
.sendKeys("f")
.keyUp(Keys.CONTROL)
.sendKeys("ss")
.build();
select.perform();
OR by using robot class(Not recommended )
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)
{
}
Hope it will help you :)