diff --git a/src/Selenium2Library/keywords/_selectelement.py b/src/Selenium2Library/keywords/_selectelement.py index 4c4e14edf..1f0b6cd37 100644 --- a/src/Selenium2Library/keywords/_selectelement.py +++ b/src/Selenium2Library/keywords/_selectelement.py @@ -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`. diff --git a/test/acceptance/keywords/lists.robot b/test/acceptance/keywords/lists.robot index 6f6776985..694fe33f1 100644 --- a/test/acceptance/keywords/lists.robot +++ b/test/acceptance/keywords/lists.robot @@ -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