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


免責聲明!

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



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