Skip to main content

Posts

Showing posts with the label select

Selenium: Get DropDown Options

How to get the options of a dropdown list? Here are the ways to get it: Option 1: - There is a built in function in selenium getselectoptions() which can be called to get the list of options available for the select tag. For ex: string[] dropDownItems = selenium.GetSelectOptions("//select[@id='someid']"); Option 2: - If you want to get the text of the dropdown items which are in this format Option One Option Two then you can get the text for the options using: var iCount = (int) selenium.GetXpathCount("//select[@id='someid']/option"); var optionsList = new List (); for (int i = 1; i { String option = selenium.GetText("//select[@id='someid']/option[" + i + "]"); optionsList.Add(option); } Option 3: To get the id for the select options. We need the following code: var iCount = (int) selenium.GetXpathCount("//select[@id='someid']/option"); var optionsList = new List (); for (int i = 1; i { String option =...