How do you fix the "element not interactable" exception?
Solution 1
A possibility is that the element is currently unclickable because it is not visible. Reasons for this may be that another element is covering it up or it is not in view, i.e. it is outside the currently view-able area.
Try this
from selenium.webdriver.common.action_chains import ActionChains
button = driver.find_element_by_class_name(u"infoDismiss")
driver.implicitly_wait(10)
ActionChains(driver).move_to_element(button).click(button).perform()
Solution 2
I just ran into a similar issue and was able to fix it by waiting until the button was "clickable".
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option('useAutomationExtension', False)
browser = webdriver.Chrome('./chromedriver', options=chrome_options)
browser.get(('YOURWEBSITEHERE.COM'))
button = WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, 'button.dismiss')))
button.click()
Solution 3
For those discovering this now and the above answers didn't work, the issue I had was the screen wasn't big enough. I added this when initializing my ChromeDriver, and it fixed the problem:
options.add_argument("window-size=1200x600")
Solution 4
The error "Message: element not interactable" mostly occurs when your element is not clickable or it is not visible yet, and you should click or choose one other element before it. Then your element will get displayed and you can modify it.
You can check if your element is visible or not by calling is_displayed()
method like this:
print("Element is visible? " + str(element_name.is_displayed()))
Solution 5
right-click and copy full xpath like below example it will work for sure
driver.find_element_by_xpath("/html/body/div[1]/div[3]/form/div[1]/div[1]/div[3]/center/input[1]").click()
Comments
-
Rolodophone almost 2 years
I know this has been asked lots of times before but how do you get around the "element not interactable" exception?
I'm new to Selenium so excuse me if I get something wrong.
Here is my code:
button = driver.find_element_by_class_name(u"infoDismiss") type(button) button.click() driver.implicitly_wait(10)
Here is the HTML:
<button class="dismiss infoDismiss"> <string for="inplay_button_dismiss">Dismiss</string> </button>
And here is the error message:
selenium.common.exceptions.ElementNotInteractableException: Message:
After is says message there is literally nothing.
I have spent lots of time searching the web, not finding anything that solves my issue. I would really appreciate an answer.
Thanks in advance.
Edit: Changed "w" to driver so it is easier to read
Update: I have just realized that I've found the HTML of the wrong button! The real button HTML is below:
<button class="dismiss"> <string for="exit">Dismiss</string> </button>
Also, I've used the answers and comments and edited my code to look like this:
button = driver.find_element_by_css_selector("button.dismiss") w.implicitly_wait(10) ActionChains(w).move_to_element(button).click(button)
And now I get a new error:
selenium.common.exceptions.WebDriverException: Message: Tried to run command without establishing a connection
The error happens in line 1:
button = driver.find_element_by_css_selector("button.dismiss")
Note: I really appreciate the help that has been given, thanks
-
Rolodophone almost 7 yearsI've tried that but it still doesn't seem to click it. It doesn't click it but it doesn't raise an error either.
-
EyuelDK almost 7 yearsI suggest you check if it is ACTUALLY being clicked. Add some click event listeners on the element to see if a click is being performed instead of visually inspecting a click.
-
zypro almost 5 yearsI would name this a "work around" then a solution. But, well... :-D
-
apascualb over 4 yearsRolodophone, in that situation you describe, please try ActionChains(driver).move_to_element(button).click(button).perform(), that is, add ".perform()".
-
EyuelDK over 4 years@apascualb made the correction, thanks for the heads up.
-
Douy789 almost 4 yearsWhere does the variable
browser
come from? -
Adam Polak Moetsi almost 4 years@Douy789 I edited the comment to answer your question
-
Invictus over 3 yearsI am facing a similar problem, my question raised here: stackoverflow.com/questions/63316796/… . button=driver.find_element_by_xpath("//*[@id='submitMe']") driver.implicitly_wait(10) ActionChains(driver).move_to_element(button).click(button).perform() I get error Message: javascript error: Failed to execute 'elementsFromPoint' on 'Document': The provided double value is non-finite.
-
vitaliis over 3 yearsWhy do you think so?
-
vitaliis over 3 yearsUsing sleep() is considered to be a bad practice in test automation.
-
NegativeFriction over 3 yearsThis doesn't account for any sort of issue where the element wouldn't be interactable yet, such as a loading overlay. This answer is not useful.
-
Adam Polak Moetsi about 3 years@zypro I do not think it is a "work around", this waits until the button is interactable (clickable) which is the issue in the posted situation :)
-
Abdessamad139 almost 3 yearsYour simple solution really saved my day :D. All above solutions did not worked for me.
-
Nicolas Gervais over 2 yearsIt can also be outside of sight because the browser window is too small. Try
options.add_argument("--disable-notifications")
-
Admin over 2 yearsAs 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.
-
Gülsen Keskin over 2 yearsThis really works thak you so much
-
Giles Knap about 2 yearsGood Answer, not a workaround! - I tried many things before reading this post. In my case the element is definitely becoming visible before it is clickable, presumably because I only just revealed it with the previous click.
-
Clang about 2 yearsThis also worked for me (actually, with the relative xpath). Does anyone have an explanation why xpath does the trick in these cases?
-
Valentin Garreau about 2 yearsthis should be the right answer !