4

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
  • 183,867
  • 41
  • 278
  • 352
Sawitree Cha
  • 189
  • 1
  • 4
  • 26

4 Answers4

4

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
  • 183,867
  • 41
  • 278
  • 352
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,555
  • 3
  • 21
  • 29
0

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()

SThanga
  • 1
  • 1
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 22 '22 at 23:31
0

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