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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM