I m trying to get the dropdown lables and its Values, extract that to excel --> sheet ,which already has the expected Values. The actual values exctracted from the selenium code vs the expected values should be compared. Tried to do that , but need help.
public void checkdropdown()
{
try{
List<WebElement> dropdownsList=driver.findElements(By.xpath("//select[@ng-model='selectdropdown']/option"));
if(dropdownList.size()>0)
{
for (WebElement eachdd : dropdownList)
{
String ddname = eachdd.getText();
click(eachdd);
List<WebElement> ddvalues = driver().findElements(By,xpath("//div//span[@class='ng-binding']"));
for(WebElement eachvalue : ddvalues)
{
writeToExcel("C:\\output.xlslx", "ddvalidation", 2, int cellIndex,String data )
}
}
}
public static void setExcelData(String filepath, String sheetname, int rowIndex, int cellIndex,String data)
{
try
{
File f= new File(filepath);
FileInputStream fis = new FileInputStream(f);
Workbook wb = WorkbookFactory.create(fis);
Sheet st = wb.getSheet(sheetname);
Row r =st.getRow(rowIndex);
Cell c = r.getCell(cellIndex);
c.setCellValue(data);
// System.out.println(data);
FileOutputStream fos = new FileOutputStream(f);
wb.write(fos);
}
catch(Exception e)
{
}
}
THe output i m trying to get is attached in image. Expected section is the one which users gives and maintains. Actual values are extracted from the UI.If any value missing in any of the section, it should be highlighted.