How do you fix the "element not interactable" exception?

199,105

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()
Share:
199,105
Rolodophone
Author by

Rolodophone

Amateur programmer on Java and Python

Updated on July 09, 2022

Comments

  • Rolodophone
    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
    Rolodophone almost 7 years
    I'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
    EyuelDK almost 7 years
    I 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
    zypro almost 5 years
    I would name this a "work around" then a solution. But, well... :-D
  • apascualb
    apascualb over 4 years
    Rolodophone, in that situation you describe, please try ActionChains(driver).move_to_element(button).click(button).p‌​erform(), that is, add ".perform()".
  • EyuelDK
    EyuelDK over 4 years
    @apascualb made the correction, thanks for the heads up.
  • Douy789
    Douy789 almost 4 years
    Where does the variable browser come from?
  • Adam Polak Moetsi
    Adam Polak Moetsi almost 4 years
    @Douy789 I edited the comment to answer your question
  • Invictus
    Invictus over 3 years
    I 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).p‌​erform() I get error Message: javascript error: Failed to execute 'elementsFromPoint' on 'Document': The provided double value is non-finite.
  • vitaliis
    vitaliis over 3 years
    Why do you think so?
  • vitaliis
    vitaliis over 3 years
    Using sleep() is considered to be a bad practice in test automation.
  • NegativeFriction
    NegativeFriction over 3 years
    This 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
    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
    Abdessamad139 almost 3 years
    Your simple solution really saved my day :D. All above solutions did not worked for me.
  • Nicolas Gervais
    Nicolas Gervais over 2 years
    It can also be outside of sight because the browser window is too small. Try options.add_argument("--disable-notifications")
  • Admin
    Admin over 2 years
    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.
  • Gülsen Keskin
    Gülsen Keskin over 2 years
    This really works thak you so much
  • Giles Knap
    Giles Knap about 2 years
    Good 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
    Clang about 2 years
    This also worked for me (actually, with the relative xpath). Does anyone have an explanation why xpath does the trick in these cases?
  • Valentin Garreau
    Valentin Garreau about 2 years
    this should be the right answer !