“获取文本”命令上的陈旧元素引用异常

问题描述 投票:0回答:1

当我尝试从字段获取文本时,出现过时元素引用异常。这是代码:

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)

等待命令全部成功,但获取文本仍然失败。

python python-3.x selenium-webdriver selenium-chromedriver robotframework
1个回答
0
投票
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}
© www.soinside.com 2019 - 2024. All rights reserved.