0

I want to get values(String) listed in a dropdown, and compare those values with a predefined list of values(String). I'm trying to implement this in Selenium WebDriver using JAVA as scripting language. Can anyone please guide me through?

Situation: Suppose in a webpage there is a dropdown listing country names, I want to read those country names from dropdown, and verify each of them is present in an existing list of country names.

suvi
  • 45
  • 1
  • 5
  • The answer has some examples and there are a lot more on the Selenium site linked from his answer. You really should spend some time googling your own question before posting here. – JeffC Jun 30 '16 at 19:17

1 Answers1

0

Below is the code you can use to print the values of a drop-down. You can modify the same to compare with your input list.

WebElement dropdown = driver.findElement(By.id("provide id of the dropdown"));

List<WebElement> dropdown_values=dropdown.findElements(By.tagName("option"));

Iterator<WebElement> it=dropdown_values.iterator();
 while(it.hasNext())
  {
    System.out.println(it.next().getText());
  } 
Amit
  • 136
  • 4