1 defSelect_from_list (self, locator, *items):2 """selects ' *items ' from list identified by ' locator '3 4 If more than one value was given for a single-selection list, the last5 value would be selected. If The target list is a multi-selection list,6 and ' *items ' is a empty list, all values of the list would be selected.7 8 *items try to select by value then by label.9 Ten It's faster to the use of ' by Index/value/label ' functions. One A An exception are raised for a single-selection list if the last - value does not exist in the list and a warning for all other non- - existing items. For a multi-selection list, the exception is raised the For any and all non-existing values. - - Select list keywords work on both lists and combo boxes. Key attributes for - Select lists is ' id ' and ' name '. See ' Introduction ' For details about + locating elements. - """ +Non_existing_items = [] A atITEMS_STR = Items and "option (s) '%s '"%", ". Join (items)or "All options" -Self._info ("Selecting%s from list '%s '."%(ITEMS_STR, locator)) - -select =self._get_select_list (Locator) - - if notItems: in forIinchRange (len (select.options)): - Select.select_by_index (i) to return + - forIteminchItems: the Try: * select.select_by_value (item) $ except:Panax Notoginseng Try: - Select.select_by_visible_text (item) the except: +Non_existing_items = Non_existing_items +[item] A Continue the + ifAny (non_existing_items): - ifselect.is_multiple: $ RaiseValueError ("Options '%s ' not in list '%s '."% (", ". Join (Non_existing_items), locator)) $ Else: - ifAny (non_existing_items[:-1]): -ITEMS_STR = Non_existing_items[:-1] and "Option (s) '%s '"%", ". Join (Non_existing_items[:-1]) theSelf._warn ("%s not found within list '%s '."%(ITEMS_STR, locator)) - ifItems andITEMS[-1]inchNon_existing_items:Wuyi RaiseValueError ("Option '%s ' isn't in list '%s '."% (Items[-1], locator))
Method Name: Select_from_list (self, locator, *items)
Similar methods:
The public method selects the items that are passed in, and if multiple values are given and is Single-selection list, the last value is selected, and if the list is multi-selection and items is empty, all options will be selected
Receive parameters: Locator,*items (labels/values)
26 Rows: Use the _get_select_list (self, locator) method to return the Select Object
Selenium2library Series Keywords _selectelementkeywords select_from_list (self, locator, *items)