3

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.

undetected Selenium
  • 151,581
  • 34
  • 225
  • 281
Sawitree Cha
  • 168
  • 1
  • 3
  • 19

2 Answers2

3

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

undetected Selenium
  • 151,581
  • 34
  • 225
  • 281
0

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();
Ashish Kamble
  • 2,362
  • 3
  • 21
  • 26