示例代码:
<div class="modal-footer">
<button type="button" class="btn btn-primary btn-block" data-modal="AlertSubmitApproval" id="btn_close_modal">ตกลง</button>
</div>
我尝试点击按钮id="btn_close_modal"
但按钮似乎不可见然后机器人响应ElementNotVisibleException: Message: element not interactable
,尽管我可以手动点击。
我的机器人代码:
Request approve
Selenium2Library.Click Element &{Landing}[reqApprove]
Sleep 2s
Selenium2Library.Click Element &{Landing}[cofReq]
Sleep 2s
Selenium2Library.Wait Until Page Contains Element id=btn_close_modal timeout=20s
Sleep 3s
Selenium2Library.Click Element id=btn_close_modal
我怎样才能点击按钮id=btn_close_modal
,请有人帮忙。
所需的元素位于模态对话框所以你需要诱导WebDriver等待为了元素可见/启用您可以使用以下解决方案中的一个/两个(组合):
-
Wait Until Element Is Visible
:
Request approve
Selenium2Library.Click Element &{Landing}[reqApprove]
Sleep 2s
Selenium2Library.Click Element &{Landing}[cofReq]
Sleep 2s
Selenium2Library.Wait Until Element Is Visible xpath=//button[@class="btn btn-primary btn-block" and @id="btn_close_modal"] timeout=20s
Sleep 3s
Selenium2Library.Click Element xpath=//button[@class="btn btn-primary btn-block" and @id="btn_close_modal"]
-
Wait Until Element Is Enabled
:
Request approve
Selenium2Library.Click Element &{Landing}[reqApprove]
Sleep 2s
Selenium2Library.Click Element &{Landing}[cofReq]
Sleep 2s
Selenium2Library.Wait Until Element Is Enabled xpath=//button[@class="btn btn-primary btn-block" and @id="btn_close_modal"] timeout=20s
Sleep 3s
Selenium2Library.Click Element xpath=//button[@class="btn btn-primary btn-block" and @id="btn_close_modal"]
您可以找到有关的详细讨论Wait Until Element Is Visible
and Wait Until Element Is Enabled
in Robotframework:Selenium2Lib:等到(...)关键字 https://stackoverflow.com/questions/48948930/robotframework-selenium2lib-wait-until-keywords/48963864#48963864
参考:Selenium2库 http://robotframework.org/Selenium2Library/Selenium2Library.html#Shortcuts
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)