Selenium2Library中select frame关键字对没有name和id的frame或者iframe的处理
elenium2Library中原有的select_frame函数(对应的关键字为select frame)可根据locator选择frame,但是,若某个frame或者iframe没有id,没有name,而页面存在多个frame或者iframe,则原函数无法实现选择该frame或者iframe的功能。其原因是原函数默认locator可以唯一选择。
解决方法为修改Selenium2Library中的select_frame函数,支持索引选择功能
找到,模块_browsermanagement.py,我的python安装在如下目录:
D:\Python27\Lib\site-packages\robotframework_selenium2library-1.7.4-py2.7.egg\Selenium2Library\keywords
将代码修改为如下:修改后的select_frame函数如下:
"""Sets frame identified by `locator` as current frame ,
if 'locator' is not unique, use index
Key attributes for frames are `id` and `name.` See `introduction` for
details about locating elements.
Example:
| select_frame_by_index | tag_index=iframe | 1 |
"""
if locator.startswith("tag_index"):
elements = self._element_find(locator,False,True)
elements = elements[int(index)]
else:
element = self._element_find(locator, True, True)
self._current_browser().switch_to_frame(element)
转载:http://blog.csdn.net/happyjxt/article/details/50595876