Skip to content
15 changes: 12 additions & 3 deletions src/Selenium2Library/keywords/_selectelement.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,24 @@ class _SelectElementKeywords(KeywordGroup):

# Public

def get_list_items(self, locator):
"""Returns the values in the select list identified by `locator`.
def get_list_items(self, locator, value=False):
"""Returns the labels or values in the select list identified by `locator`.

Select list keywords work on both lists and combo boxes. Key attributes for
select lists are `id` and `name`. See `introduction` for details about
locating elements.

Example:
| ${labels1} = | Get List Items | xpath=//h1 |
| ${labels2} = | Get List Items | xpath=//h1 | value=${False} |
| ${values} = | Get List Items | xpath=//h1 | value=True |
| Should Be Equal | ${labels1} | ${labels2} |
"""
select, options = self._get_select_list_options(locator)
return self._get_labels_for_options(options)
if value:
return self._get_values_for_options(options)
else:
return self._get_labels_for_options(options)

def get_selected_list_label(self, locator):
"""Returns the visible label of the selected element from the select list identified by `locator`.
Expand Down
12 changes: 12 additions & 0 deletions test/acceptance/keywords/lists.robot
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ Get List Items From Multi-Select List
${expected}= Create List Males Females Others
Should Be Equal ${items} ${expected}

Get List Values From Single-Select List
[Documentation] Get List Values From Single-Select List
${values}= Get List Items preferred_channel value=${True}
${expected}= Create List email phone directmail
Should Be Equal ${values} ${expected}

Get List Values From Multi-Select List
[Documentation] Get List Values From Multi-Select List
${values}= Get List Items interests value=True
${expected}= Create List males females others
Should Be Equal ${values} ${expected}

Get Selected List Value
[Documentation] Get Selected List Value
${selected}= Get Selected List Value preferred_channel
Expand Down