0

I am trying to click a button, which is in the popup, but it is giving me the following error:

Message: Element <button id="modal_ok" class="btn btn-primary waves-effect waves-light" type="button"> could not be scrolled into view

My HTML content for this is:

<button type="button" id="modal_ok" onclick="$('#disable_1').hide(); $('#form_disable_1').submit();" class="btn btn-primary waves-effect waves-light">Ok</button>

The code I have written is as follows:

ok_button = browser.find_element_by_id("modal_ok")
self.assertIsNotNone(ok_button)
# ok_button.click()
WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.ID, "modal_ok"))).click()

The assert is working, which means the element is visible, but I am not able to click it because of the aforementioned error.

W. Churchill
  • 346
  • 1
  • 7
  • 28
Coder
  • 107
  • 4
  • 15

1 Answers1

1

Coder,

You can try with Javascript executor :

Code :

ok_button = browser.find_element_by_id("modal_ok")
self.assertIsNotNone(ok_button)
driver.execute_script("arguments[0].click();", ok_button)   

Or you can try with this code :

ok_button = browser.find_element_by_id("modal_ok")
self.assertIsNotNone(ok_button)
driver.execute_script("arguments[0].scrollIntoView(true);", ok_button)   
ok_button.click()
cruisepandey
  • 28,520
  • 6
  • 20
  • 38