RobotFramework做自动化中,能定位到iFrame里面,怎么在iFrame里面输入文字?

01.描述
  • RobotFramework中,能定位到iFrame里面,怎么在iFrame里面输入文字。

如下图:

02.遇到的问题
  • 基本上,不管什么原因的错误,我都记录下来了。
------------------------------------------------------------------------------
帖子内容                                                              | FAIL |
Element with locator 'Xpath=//iframe[contains(@id,'ueditor_0')]' not found.
------------------------------------------------------------------------------
------------------------------------------------------------------------------
帖子内容                                                              | FAIL |
Element with locator 'id=ueditor_0' not found.
------------------------------------------------------------------------------
------------------------------------------------------------------------------
帖子内容                                                              | FAIL |
InvalidElementStateException: Message: invalid element state
(Session info: chrome=83.0.4103.61)
------------------------------------------------------------------------------
帖子内容                                                              | FAIL |
InvalidSelectorException: Message: invalid selector: Unable to locate an element with the xpath expression /html/body'] because of the following error:
SyntaxError: Failed to execute 'evaluate' on 'Document': The string '/html/body']' is not a valid XPath expression.
(Session info: chrome=83.0.4103.61)
------------------------------------------------------------------------------
03.解决
  • 我是用谷歌插件Xpath Helper定位iFrameid="ueditor_0",图中黄色区域是定位的范围。

    def create_variables(self):
        variables = {
            '''此处部分省略,和iFrame没有关系'''
            "${selectFrame}":"Xpath=/html/body",    # 先进入iFrame中
            "${content}": "id:ueditor_0",           # 在找到iFrame中的id
        }
    def teststeps(self):
        '''此处部分省略,和iFrame没有关系'''
        test_05 = self.suite.tests.create("帖子内容")
        # 进入iFrame中
        test_05.keywords.create("Select Frame", args=["${content}"])
        # 找到iFrame的id,录入文字
        test_05.keywords.create("Input Text", args=["${selectFrame}","帖子"])
04.反思
  • 历时8个小时,我感觉我又行了,哈哈哈哈哈。

在我绝望之际,参考了:https://testerhome.com/topics/12766这个博客,给了我很大启发,如下图:

  • 期间查阅的其它资料,虽然没能解决我的问题,还是贴出来,避免遇坑。
  1. stackoverflow:https://stackoverflow.com/questions/51436532/how-to-automate-iframe-text-flied-using-robotframework

2.CSDN:https://blog.csdn.net/spanthrive12/article/details/52025469

posted @ 2020-07-17 13:25  酷酷的伊莱文  阅读(1130)  评论(0编辑  收藏  举报