0

enter image description hereI have a python3 selenium script on Ubuntu running in chrome successfully when I attempt to run headless it errors out on element not being interactable:

Traceback (most recent call last):
  File "file.py", line 143, in <module>
    driver.find_element_by_xpath('//*[@id="ctl00_MainContent_MyReportViewer_ctl04_ctl00"]').click()                  
  File "/home/jobs/.local/lib/python3.8/site-packages/selenium/webdriver/remote/webelement.py", line 80, in click                      
    self._execute(Command.CLICK_ELEMENT)
  File "/home/jobs/.local/lib/python3.8/site-packages/selenium/webdriver/remote/webelement.py", line 633, in _execute                      
    return self._parent.execute(command, params)
  File "/home/jobs/.local/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute                      
    self.error_handler.check_response(response)
  File "/home/jobs/.local/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response                      
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable                      
  (Session info: headless chrome=87.0.4280.88

I'd seen a post on that it might be how chrome interacts with objects differently so I've tried this with Firefox as well with the same results.

The only line I'm changing is:

chrome_options.add_argument("--headless")

1 Answer 1

1

This error message...

selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable

...implies that the desired WebElement wasn't interactable when you invoked click on it.

The element seems to be a dynamic element, so to click on the element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "#ctl00_MainContent_MyReportViewer_ctl04_ctl00"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//*[@id="ctl00_MainContent_MyReportViewer_ctl04_ctl00"]"))).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
    

Update

In you are still unable to click on the element as an alternative you can use the ActionChains as follows:

  • Using CSS_SELECTOR:

    element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "#ctl00_MainContent_MyReportViewer_ctl04_ctl00")))
    ActionChains(driver).move_to_element(element).click(element).perform()
    
  • Using XPATH:

    element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//*[@id="ctl00_MainContent_MyReportViewer_ctl04_ctl00"]")))
    ActionChains(driver).move_to_element(element).click(element).perform()
    
  • 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
    from selenium.webdriver.common.action_chains import ActionChains
    
Sign up to request clarification or add additional context in comments.

2 Comments

I tried with the WebDriverWait set to 20 and then 30 with no success. I took the screenshot during the running to see what was happening and I am thinking that Selenium maybe not see the full screen. That could be a red herring though. I've attached the screenshot above.
@StephenYorke Checkout the updated answer and let me know the status.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.