5

I am trying to automate an access point web configuration. During this, I get a pop up (kind of an overlay with "Yes" and "No") which i want to click on

The HTML code for the overlay that I am trying to click on:

<div id="generic-warning-dialog" class="dialog exclamation text-orphan" style="">
<div class="warning-content dialog-content text-orphan">Security Mode is disabled on one or more of your wireless networks. Your network could be open to unauthorized users. Are you sure you wish&nbsp;to&nbsp;proceed?</div>
    <div class="dialog-buttons text-orphan">
        <button class="cancel">No</button>
        <button class="submit" style="display: block;">Yes</button>
    </div>
</div> 

I tried

browser.find_element_by_class_name("submit").click()

but I get the following error:

raise exception_class(message, screen, stacktrace) selenium.common.exceptions.ElementClickInterceptedException: Message: Element is not clickable at point (788,636.5) because another element obscures it

Can you please advise on how should i proceed? I am using firefox and python

Andersson
  • 51,635
  • 17
  • 77
  • 129
Klot
  • 83
  • 1
  • 2
  • 5
  • Possible duplicate of [Debugging "Element is not clickable at point" error](https://stackoverflow.com/questions/11908249/debugging-element-is-not-clickable-at-point-error) – eduPeeth Jul 25 '18 at 05:07
  • try to give explicit wait before clicking on the element. – Gautam Bothra Jul 25 '18 at 05:09
  • How Does the explicit wait help? I tried it through the python console by giving each individual command so I don’t think it’s got to do with the page not getting loaded. – Klot Jul 25 '18 at 05:13
  • This is not an issue with Python. This is an issue with Selenium and Firefox. – Daniel Viglione Sep 05 '19 at 20:28

2 Answers2

6

You can Replace click event with action class

Using Action Class :

from selenium.webdriver.common.action_chains import ActionChains

actions = ActionChains(driver)
actions.move_to_element("Your Web Element").click().perform()
Ishita Shah
  • 3,955
  • 2
  • 27
  • 51
  • for the "Your web element" i used >>> element=browser.find_element_by_class_name("submit") >>> actions = ActionChains(browser) >>> actions.move_to_element(element).click().perform() Is that correct? This does not work – Klot Jul 25 '18 at 07:03
  • @Klot Yes correct. If not working, What is an exception ? – Ishita Shah Jul 25 '18 at 07:13
  • Did not get any error but it was unable to click the button. The overlay window was still being displayed after executing this. – Klot Jul 25 '18 at 13:52
5

As per your question and the HTML you have shared, you need to induce WebDriverWait for the desired element to be clickable and you can use the following solution:

#to click on Yes button
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='warning-content dialog-content text-orphan' and contains(.,'Security Mode is disabled')]//following::div[1]//button[@class='submit']"))).click()
# to click on No button
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='warning-content dialog-content text-orphan' and contains(.,'Security Mode is disabled')]//following::div[1]//button[@class='cancel']"))).click()

Note : You have to add the following imports :

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • I get this error WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='warning-content dialog-content text-orphan' and contains(.,'Security Mode is disabled')]//button[@class='submit']"))).click() Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/support/wait.py", line 80, in until raise TimeoutException(message, screen, stacktrace) – Klot Jul 25 '18 at 07:15
  • @Klot Checkout my updated answer and let me know the status – undetected Selenium Jul 25 '18 at 07:23
  • @ DebanjanB upvoted the answer. can you explain how the command works – Klot Jul 25 '18 at 07:47
  • @Klot In my solution I have induced a waiter to wait for the _element to turn clickable_ and once the state of the element becomes intractable we invoked `click()` method directly. let me know if you have any further queries. – undetected Selenium Jul 25 '18 at 08:20
  • 5
    This did not work for me. It seems like button is already "clickable" but clicking it still leads to "obscure error" - in my case it is a button within a foundation reveal/modal (see https://foundation.zurb.com/sites/docs/reveal.html) Any ideas? – Henhuy Dec 06 '19 at 13:16
  • 1
    I've got the same problem as @Henhuy. Even though I wait for the element to be clickable, it still throws `ElementClickInterceptedException`. I will just go with `invisibility_of_element` to wait for the blocking object to become invisible. – Burak Kaymakci Sep 09 '20 at 23:37