1

I am using selenium with java. I have a huge drop down list alike this and I want to select this Dropdown list and get all options values in Java array so that I could print that or compare with another array. Can anyone please help me

<select id="cityID" name="cityID" class="">

<option value="">- Select city for Alaska - </option>
<option value="129467">Adak</option>
<option value="202770">Akhiok</option>
<option value="44455">Akiachak</option>
<option value="35798">Eielson Afb</option>
<option value="232756">Eielson Air Force Base</option>
<option value="152259">Elim</option>
<option value="22639">Elmendorf Afb</option>
<option value="182039">Emmonak</option>
<option value="117516">Yakutat</option>
</select>
1
  • 1
    Please read How to Ask. Please provide the code you have tried and the execution result including any error messages, etc. Commented Mar 15, 2017 at 19:26

1 Answer 1

2
WebElement drop_down =driver.findElement(By.id("cityID"));
Select se = new Select(drop_down);
List<WebElement> options = se.getOptions();

Then you can iterate over this list and do .getText();

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.