0

In the given code, I need the list of the value of the "value" attribute for each of the options in the select drop-down :

<select id="myselect">
<option value="val1">Some Text</option>
<option value="val2">Some Text</option>
<option value="val3">Some Text</option>
<option value="val4">Some Text</option>
<option value="val5">Some Text</option>
<option value="val6">Some Text</option>
</select>

I want the list of all the values, which is {val1,val2,val3,val4,val5,val6}

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Shivani
  • 36
  • 7
  • What have you tried already? Please provide some code. – Chris Jun 20 '19 at 11:13
  • Possible duplicate of [How to get list of values from dropdown list with selenium and python](https://stackoverflow.com/questions/56662616/how-to-get-list-of-values-from-dropdown-list-with-selenium-and-python) – Moshe Slavin Jun 20 '19 at 11:14
  • try using `Select` you can see an example in the answer: https://stackoverflow.com/a/56662968/8179099 – Moshe Slavin Jun 20 '19 at 11:15

1 Answers1

1

To create a List of all the values of the value attribute for each of the options with in the <select> tag you can use the following Java based solution:

Select dropDownSelect = new Select(driver.findElement(By.id("myselect")));
List<WebElement> dropDownActualValues = dropDownSelect.getOptions();
for(WebElement element:dropDownActualValues)
    System.out.println(element.getAttribute("value"));
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352