ElementNotVisibleException: Message: element not interactable in Robot Framework

Sawitree Cha picture Sawitree Cha · Nov 1, 2018 · Viewed 7.7k times · Source

Example code:

<div class="modal-footer">
   <button type="button" class="btn btn-primary btn-block" data-modal="AlertSubmitApproval" id="btn_close_modal">ตกลง</button>
</div>

I try to click the button id="btn_close_modal" but it seems like the button is not visible then robot response ElementNotVisibleException: Message: element not interactable, in spite of the fact I able to click by manual.

My robot code:

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

How can I able to click the button id=btn_close_modal, please could anyone help.

Answer

DebanjanB picture DebanjanB · Nov 1, 2018

The desired element is within a Modal Dialog Box so you need to induce WebDriverWait for the element to be visible/enabled and you can use either/both (clubbing up) of the following solutions:

  • 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"]
    
  • You can find a detailed discussion about Wait Until Element Is Visible and Wait Until Element Is Enabled in Robotframework: Selenium2Lib: Wait Until (…) Keywords

  • Reference: Selenium2Library