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}

3

1 Answer 1

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"));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.