Sawitree Cha
Sawitree Cha

Reputation: 199

ElementNotVisibleException: Message: element not interactable in Robot Framework

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.

Upvotes: 4

Views: 19111

Answers (5)

AdrienW
AdrienW

Reputation: 3462

If the other answers do not help, try running the test on another monitor or in headless mode.

For me, the error appeared when running the test browser on a 1440p monitor but everything was fine with headlesschrome or on a 1080p monitor.

Upvotes: 0

SAID Med Bechir
SAID Med Bechir

Reputation: 109

Try to use Press keys instead of Click Element. Press Keys locator_here ENTER or Press Keys locator_here SPACE

Upvotes: 0

SThanga
SThanga

Reputation: 1

Try this : if Error element not interactable in the robot selenium frame work to button or checkbox etc..

Execute JavaScript $(id=btn_close_modal).click()

Upvotes: 0

undetected Selenium
undetected Selenium

Reputation: 193388

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

Upvotes: 4

Ashish Kamble
Ashish Kamble

Reputation: 2625

try using this,

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

or try using java script executor,

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

Upvotes: 0

Related Questions