Selenium2Library系列 keywords 之 _SelectElementKeywords 之 unselect_from_list(self, locator, *items)

时间:2021-04-01 16:21:13
     def unselect_from_list(self, locator, *items):
"""Unselects given values from select list identified by locator. As a special case, giving empty list as `*items` will remove all
selections. *items try to unselect by value AND by label. It's faster to use 'by index/value/label' functions. 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.
"""
items_str = items and "option(s) '%s'" % ", ".join(items) or "all options"
self._info("Unselecting %s from list '%s'." % (items_str, locator)) select = self._get_select_list(locator)
if not select.is_multiple:
raise RuntimeError("Keyword 'Unselect from list' works only for multiselect lists.") if not items:
select.deselect_all()
return select, options = self._get_select_list_options(select)
for item in items:
select.deselect_by_value(item)
select.deselect_by_visible_text(item)

方法名:unselect_from_list(self, locator, *items)

相似方法:

公共方法 移除所给items的选中状态

接收参数:locator,*labels/*values

18行:使用_get_select_list(self, locator)方法,返回Select对象