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对象

Selenium2Library系列 keywords 之 _SelectElementKeywords 之 select_from_list(self, locator, *items)的更多相关文章

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

    def unselect_from_list(self, locator, *items): """Unselects given values from select ...

  2. Selenium2Library系列 keywords 之 _SelectElementKeywords 之 list_selection_should_be(self, locator, *items)

    def list_selection_should_be(self, locator, *items): """Verifies the selection of sel ...

  3. Selenium2Library系列 keywords 之 _SelectElementKeywords 之 unselect_from_list_by_label(self, locator, *labels)

    def unselect_from_list_by_label(self, locator, *labels): """Unselects `*labels` from ...

  4. Selenium2Library系列 keywords 之 _SelectElementKeywords 之 unselect_from_list_by_value(self, locator, *values)

    def unselect_from_list_by_value(self, locator, *values): """Unselects `*values` from ...

  5. Selenium2Library系列 keywords 之 _SelectElementKeywords 之 unselect_from_list_by_index(self, locator, *indexes)

    def unselect_from_list_by_index(self, locator, *indexes): """Unselects `*indexes` fro ...

  6. Selenium2Library系列 keywords 之 _SelectElementKeywords 之 select_from_list_by_label(self, locator, *labels)

    def select_from_list_by_label(self, locator, *labels): """Selects `*labels` from list ...

  7. Selenium2Library系列 keywords 之 _SelectElementKeywords 之 select_from_list_by_value(self, locator, *values)

    def select_from_list_by_value(self, locator, *values): """Selects `*values` from list ...

  8. Selenium2Library系列 keywords 之 _SelectElementKeywords 之 list_should_have_no_selections(self, locator)

    def list_should_have_no_selections(self, locator): """Verifies select list identified ...

  9. Selenium2Library系列 keywords 之 _SelectElementKeywords 之 get_selected_list_values(self, locator)

    def get_selected_list_values(self, locator): """Returns the values of selected elemen ...

随机推荐

  1. Struts2笔记——利用token防止表单重复提交

    在一些项目中经常会让用户提交表单,当用户点击按钮提交后,如果再次浏览器刷新,这就会造成表单重复提交,若是提交的内容上传至服务器并请求数据库保存,重复提交的表单可能会导致错误,然后跳转到错误界面,这是一 ...

  2. Struts2笔记——struts常用标签

    使用struts标签前,首先要配置struts2架构,然后导入标签库,jsp插入如下语句: <%@taglib uri="/struts-tags" prefix=" ...

  3. logback与Log4J的区别

    原文:http://blog.csdn.net/lwzcjd/article/details/5617200 Logback和log4j是非常相似的,如果你对log4j很熟悉,那对logback很快就 ...

  4. Android百度地图开发04之POI检索

    POI检索 POI~~~ Point of Interest,翻译过来就是“兴趣点”.我们在使用地图的时候,搜索周边的ktv,饭店,或者宾馆的时候,输入关键字,然后地图展示给我们很多个点, 这些点就是 ...

  5. Javascript获取浏览器窗口大小 获取屏幕,浏览器,网页高度宽度

    /******************** * 取窗口滚动条高度  ******************/function getScrollTop(){    var scrollTop=0;    ...

  6. USACO Section 2.4: Bessie Come Home

    因为题目给了边的信息,所以比较适用bell-man的方法 /* ID: yingzho1 LANG: C++ TASK: comehome */ #include <iostream> # ...

  7. c# 计算一个整型数组的平均

    一个整型数组的平均: class Program { static void Main(string[] args) { ,,,,,,,,,}; double avg= GetAvg(array); ...

  8. eclipse中maven项目部署到tomcat

    其实maven项目部署到tomcat的方式很多,我从一开始的打war包到tomcat/webapps目录,到使用tomcat-maven插件,到直接使用servers部署,一路来走过很多弯路. 下面就 ...

  9. java.lang.NoSuchFieldError: VERSION_2_3_0 报错解决方案

    java.lang.NoSuchFieldError: VERSION_2_3_0 at org.apache.struts2.views.freemarker.FreemarkerManager.c ...

  10. CVS数据的导入和导出

    2.CSV导入/导出测试 package junit.test; import java.io.File; import java.util.ArrayList; import java.util.L ...