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


     1     def select_from_list(self, locator, *items):
     2         """Selects `*items` from list identified by `locator`
     3 
     4         If more than one value is given for a single-selection list, the last
     5         value will be selected. If the target list is a multi-selection list,
     6         and `*items` is an empty list, all values of the list will be selected.
     7 
     8         *items try to select by value then by label.
     9 
    10         It's faster to use 'by index/value/label' functions.
    11 
    12         An exception is raised for a single-selection list if the last
    13         value does not exist in the list and a warning for all other non-
    14         existing items. For a multi-selection list, an exception is raised
    15         for any and all non-existing values.
    16 
    17         Select list keywords work on both lists and combo boxes. Key attributes for
    18         select lists are `id` and `name`. See `introduction` for details about
    19         locating elements.
    20         """
    21         non_existing_items = []
    22 
    23         items_str = items and "option(s) '%s'" % ", ".join(items) or "all options"
    24         self._info("Selecting %s from list '%s'." % (items_str, locator))
    25 
    26         select = self._get_select_list(locator)
    27 
    28         if not items:
    29             for i in range(len(select.options)):
    30                 select.select_by_index(i)
    31             return
    32 
    33         for item in items:
    34             try:
    35                 select.select_by_value(item)
    36             except:
    37                 try:
    38                     select.select_by_visible_text(item)
    39                 except:
    40                     non_existing_items = non_existing_items + [item]
    41                     continue
    42 
    43         if any(non_existing_items):
    44             if select.is_multiple:
    45                 raise ValueError("Options '%s' not in list '%s'." % (", ".join(non_existing_items), locator))
    46             else:
    47                 if any (non_existing_items[:-1]):
    48                     items_str = non_existing_items[:-1] and "Option(s) '%s'" % ", ".join(non_existing_items[:-1])
    49                     self._warn("%s not found within list '%s'." % (items_str, locator))
    50                 if items and items[-1] in non_existing_items:
    51                     raise ValueError("Option '%s' not in list '%s'." % (items[-1], locator))

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

    相似方法:

    公共方法 选中所传入items,如果给了多个值,并且是single-selection list,则最后一值会被选中;如果是 multi-selection list,并且items为空,则所有options都会被选中

    接收参数:locator,*items(labels/values)

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

  • 相关阅读:
    linux清理内存
    华为代码注释标准
    Spring缓存机制的理解
    jQuery实现动态分割div—通过拖动分隔栏实现上下、左右动态改变左右、上下两个相邻div的大小
    模仿iframe框架,由分隔栏动态改变左右两侧div大小———基于jQuery
    js实现由分隔栏决定两侧div的大小—js动态分割div
    java基于socket的简单聊天系统
    中国移动归属地区号大全
    将本地光盘做成yum源
    windows下设置计划任务自动执行PHP脚本
  • 原文地址:https://www.cnblogs.com/loveok-56/p/4464273.html
Copyright © 2020-2023  润新知