python - 元素不可见异常 : Message: element not interactable in Robot Framework

标签 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:消息:元素不可交互,尽管如此事实上我可以手动点击。

我的机器人代码:

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

最佳答案

所需的元素位于模态对话框中,因此您需要引发WebDriverWait以使元素可见/启用,并且您可以使用以下解决方案中的一个/两个(组合):

  • 等待元素可见:

    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"]
    
  • 等待元素启用:

    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

关于python - 元素不可见异常 : Message: element not interactable in Robot Framework,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53097684/

相关文章:

python - 如何在 Django 中生成自定义表单?

python - Selenium/Python - 如何按随机选择的像素滚动?

java - Assert + Selenium 4 相对定位器

javascript - getText() 在 Selenium 中返回一个空白,即使文本没有被隐藏。我也试过 JavaScript

automation - 如何处理机器人框架中的警报?

robotframework - 如何在 Robot 框架中用 2 行代码编写代码

python如何将css文件解析为键值

python - 在 Python 中使用 Tesseract OCR 的 UnicodeDecodeError 'charmap' 编解码器

python - 如何使用ImageMagick覆盖特殊框架中的图片?

python - 从 python 脚本执行机器人框架文件