我正在创建一个新脚本,在其中更改设置然后保存。选择"保存"按钮后,屏幕屏蔽将其本身,请等待...消息在页面的右下角显示。我希望我的脚本等待此消息不再显示然后注销。我看到的当前行为是脚本继续并在显示等待消息时选择"注销"按钮。
我正在使用骑行来编辑脚本,看起来像这样:
Click Element id=save
Wait Until Keyword Succeeds 30 sec 1 sec Page should not contain element xpath=//*[text()='Please wait…']
${Status} Run Keyword and return status Page Should Not Contain Element xpath=//*[text()='Please wait…']
Run Keyword If ${Status}=="True" Click Element id=logout
此测试案例成功运行而没有错误。它只是不在等待页面完成更新和保存新设置。
问题可能是将您的应用程序带到"请等待"消息之前将您的应用程序带到几百毫秒之前。因此,当关键字运行直到页面不包含该元素时,关键字立即退出,因为它尚未在页面上。
一个简单的解决方案是等待它出现在您等待它消失之前:
Wait Until Page Contains element xpath=//*[text()='Please wait…'] timeout=5
Wait Until Page does NOT contain element xpath=//*[text()='Please wait…'] timeout=30
在@bryan Oakley的答案上扩展,以下内容与您的问题中提供的示例更加内联。我已经使用以下HTML页面创建了一个POC,在其中2秒后将消息从按下按钮后出现,然后在5秒后消失:
:<html>
<head>
<script>
function myFunction() {
setTimeout(function () {
document.getElementById("demo").innerHTML = "Please wait...";
}, 2000);
setTimeout(function () {
document.getElementById("demo").innerHTML = "";
}, 5000);
}
</script>
</head>
<body>
<button id="save" type="button" onclick="myFunction()">save</button>
<p id="demo"></p>
</body>
</html>
使用以下机器人脚本,我使用了与@bryan Oakley相似的关键字,但也对其进行了格式化,以使其在SO中更可读。
*** Settings ***
Library Selenium2Library
*** Test Cases ***
TC1
Open Browser http://localhost:8090/waitfor/ browser=Chrome
Click Element id=save
Wait Until Page Contains element
... xpath=//p[text()='Please wait...']
... 5s
${Status} Run Keyword and return status
... Wait Until Keyword Succeeds
... 10s
... 1s
... Page should not contain element
... xpath=//*[text()='Please wait...']
Run Keyword If
... ${Status}==${True}
... Log To Console n Status is True
[Teardown] Close Browser