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, 2020 in Selenium by Jyra
• 580 points
4,439 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, 2020 in Selenium by Sirajul
• 59,230 points
1,790 views
+1 vote
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 11, 2019 in Selenium by Sneha
28,324 views
0 votes
3 answers

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

Try using List <WebElement> to access all similar elements ...READ MORE

answered Dec 16, 2020 in Selenium by Roshni
• 10,520 points
81,580 views
0 votes
1 answer
0 votes
2 answers

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,500 points
12,619 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
8,572 views
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,910 points
6,629 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,519 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP