Automation Using Selenium Webdriver

Monday 17 October 2016

How to compare values from the list or from dropdown list in webdriver (Java)

Currently working on Selenium WebDriver and using Java for scripting.
I have stored all drop down values of db in property file and want to compare same values whether they are in UI as in DropDown options.
The visualization.txt which is in C: directory contains the below options visualizationId=Month
So How can I compare both values are matching. I need to get all the drop down options from property file i.e visualization.txt then need to check in the drop drop down in UI

public class Ex1 {
private WebDriver d;
@Test
public void testUntitled() throws Exception {
d = new FirefoxDriver();
d.get("http://register.rediff.com/commonreg/index.php?redr=http://portfolio.rediff.com/money/jsp/loginnew.jsp?redr=home");

String[] exp = {"Month", "JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"};
WebElement dropdown = d.findElement(By.id("date_mon"));
        Select select = new Select(dropdown);

        List<WebElement> options = select.getOptions();
        for(WebElement we:options)
        {
         for (int i=0; i<exp.length; i++){
             if (we.getText().equals(exp[i])){
             System.out.println("Matched");
             }
           }
         }  }}


OUTPUT:
Mateched
Mateched
Mateched
Mateched
Mateched
Mateched
Mateched
Mateched
Mateched
Mateched
Mateched
Mateched

No comments:

Post a Comment