How to get all the values from dropdown

I need to get all the values from the drop down and store them in an array/write to excel file

u can try and define a Keyword , for a method that will capture all of the dropdown values inside a list , and than return the list.

for example , a method that collects all dropdown values and click on one of them

@Keyword
def clickOnDropDownIndex(TestObject to,int i){

List dropdownval = WebUiBuiltInKeywords.findWebElements(to,30);
dropdownval[i].click();
}

but u can change it just return the list or write it somewhere.

in this example , TestObject TO , is the webelement that holds all of the dropdown values (UL )

don’t forget to add selenium jar …and import to the keyword class.

import org.openqa.selenium.WebElement

Hi there,

Please use ‘Get Text’ keyword and then store it to the variable you want, e.g:

result = WebUI.``getText``(findTestObject(``'link_Register'``))

Hi there,

You can’t capture option in the dropdown list. The captured object will always be dropdown list. So it’s better to capture the list and then use it as a test object to select the second option.

Thanks

I don’t want to verify the texts present in the dropdown.

Suppose I have a drop down with 3 values(say A, B, C). I need to read these values and store them somewhere(may be an array/excel sheet).

Thank you.

Hi there,

You can either use ‘Verify Option Present By Label’ or ‘Verify Option Present By Value’ to solve your case.

Thanks

In Katalon Studio 5.3.1, I found I had to handle a drop-down like this:

Entries = WebUI.getNumberOfTotalOption(findTestObject(‘Page/select_Entry’))
** for** (def Entry : 0…Entries-1) {
WebUI.selectOptionByIndex(findTestObject(‘Page/select_Entry’), Entry, FailureHandling.CONTINUE_ON_FAILURE)
// do things; a .each loop might be the more Groovy coding style
}

All options of a drop-down are returned as one multi-line string by
WebUI.gettext(findTestObject(‘Page/select_Entry’), FailureHandling.CONTINUE_ON_FAILURE)

Groovy being renowned for its list features, how does one most elegantly

  • get only the selected item(s) ?
  • iterate through the lines of one such string (rather than ByIndex),
    possibly transformed to list/array ?

Further add-on to the above can be accomplished using java code:

int Entries = WebUI.getNumberOfTotalOption(findTestObject(‘Page/Select_Entry’))

for (def Entry : (0…Entries - 1))

{
WebUI.selectOptionByIndex(findTestObject(‘Page/select_Entry’), Entry, FailureHandling.CONTINUE_ON_FAILURE)

String Option = new Select(driver.findElement(By.id(“Option”))).getFirstSelectedOption().getText();

Assert.assertTrue(Option.equalsIgnoreCase(“Something”))

}

Is anyone write function for ios? Because I can just click dropdown and can not reach list
@Ashwary Soni