Get dropdown name and the list of dropdwn values, Write the result data to Excel sheet from a particular Column and Row in Java

0 votes

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.

Actula Vs Expected

Apr 22 in Selenium by Jyra
• 490 points
140 views
So basically, your query is regarding comparison of the extracted value with the existing values in the excel. Is it?
Yes Zenith. While extracting the values from UI, it should input those values to excel and then do comparision.

Hi, @Jyra,

Regarding your query, you can try something like this:https://www.swtestacademy.com/data-driven-excel-selenium/

Sure Roshni. thanks

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Selenium

+3 votes
1 answer

How to read excel file numeric data of all rows and column in selenium? I have 10 rows and 5 column but I read Only String value not a Numeric value?

Hey, @Mahendra, check this thread https://www.edureka.co/community/52170/read-numeric-data-from-excel-sheet-using-selenium-webdriver It deals with ...READ MORE

answered Jan 27 in Selenium by Sirajul
• 53,080 points
243 views
0 votes
1 answer

How to get the HTML source of a webpage using Selenium in Java?

There is a method called getPageSource() in ...READ MORE

answered Jan 10, 2019 in Selenium by Sneha
6,987 views
0 votes
1 answer

How to print text from a list of all web elements with same class name in Selenium?

@Rajni, following test case is somewhat similar ...READ MORE

answered Jun 20, 2019 in Selenium by Avantika
11,563 views
0 votes
1 answer

How to get list of tests from Test Explorer in VS

Select all tests in Test Explorer and ...READ MORE

answered Aug 1, 2018 in Selenium by Samarpit
• 5,870 points
139 views
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,510 points
2,611 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,870 points
2,055 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,870 points
2,164 views