当我尝试从字段获取文本时,出现过时元素引用异常。这是代码:
Get Text
[Arguments] ${locator}
Wait For Condition return document.readyState=="complete"
Wait Until Page Contains Element ${locator}
Wait Until Keyword Succeeds 5 5 Identify Element ${locator}
Wait Until Element Is Visible ${locator}
Sleep 2s
${text} SeleniumLibrary.Get Text ${locator}
[Return] ${text}
我在 ${text} SeleniumLibrary.Get Text ${locator} 命令上收到以下错误:
StaleElementReferenceException: Message: stale element reference: stale element not found (Session info: chrome=120.0.6099.225)
等待命令全部成功,但获取文本仍然失败。
Get Text
[Arguments] ${locator}
Wait For Condition return document.readyState=="complete"
Wait Until Page Contains Element ${locator}
Wait Until Keyword Succeeds 5 5 Identify Element ${locator}
Wait Until Element Is Visible ${locator}
Sleep 2s
${text}= Set Variable ${EMPTY}
:FOR ${INDEX} IN RANGE 3
\ Run Keyword And Ignore Error # Retry up to 3 times
\ ... ${text}= SeleniumLibrary.Get Text ${locator}
\ ... Exit For Loop If '${text}' != '${EMPTY}' # Break the loop if text is retrieved
\ ... Sleep 2s # Wait before retrying
[Return] ${text}