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
定位iFrame
中id="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這個博客,給了我很大啟發,如下圖:
- 期間查閱的其它資料,雖然沒能解決我的問題,還是貼出來,避免遇坑。
- stackoverflow:https://stackoverflow.com/questions/51436532/how-to-automate-iframe-text-flied-using-robotframework
2.CSDN:https://blog.csdn.net/spanthrive12/article/details/52025469