ElementNotVisibleException:消息:元素在Robot Framework中不可交互

时间:2018-11-01 08:38:24

标签: python selenium robotframework element webdriverwait

示例代码:

<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,请任何人帮忙。

2 个答案:

答案 0 :(得分:1)

所需元素位于模态对话框中,因此您需要引入 WebDriverWait 以便使元素可见/启用,并且您可以(结合使用)以下解决方案之一/全部:

  • 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"]
    
  • 您可以在Robotframework: Selenium2Lib: Wait Until (…) Keywords

    中找到有关Wait Until Element Is VisibleWait Until Element Is Enabled的详细讨论
  • 参考:Selenium2Library

答案 1 :(得分:0)

尝试使用它,

Click Element       //button[@id='btn_close_modal']

或尝试使用Java脚本执行程序,

Wait Until Page Does Not Contain   NOBODY SELECTED
Execute JavaScript  $("#btn_close_modal").click();
相关问题