ElementNotInteractableException error when using headless option

Viewed 1172

I get error when i try and run say below code.

Error is

ElementNotInteractableException: Message: element not interactable (Session info: headless chrome=83.0.4103.116)

This seems to be happening because of chromeOptions.add_argument("--headless"). How do we inspect elements in case we are using this argument ? Note that website name provided in code is a dummy one.

Also is there a way to open the webpage in existing open browser instance instead of using a new one ?

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
import time

chromeOptions=Options()
chromeOptions.add_argument("--ignore-certificate-errors")
chromeOptions.add_argument("--incognito")
chromeOptions.add_argument("--headless")

driver = webdriver.Chrome(executable_path=r"C:/Users/lenovo/Downloads/chromedriver_win32/chromedriver.exe",options=chromeOptions)
driver.get("https://abcd.com")
ele=driver.find_element_by_name('q')
time.sleep(10)
ele.clear()
1 Answers

Try setting the window size as well as being headless. Add this:

chromeOptions.add_argument("--window-size=1920,1080")

The default size of the headless browser is tiny. If the code works when headless is not enabled it might be because your object is outside the window.

[edit - updated based feedback that the the above didn't working]

Answering your question rather than trying solving your issue.

Either add this to your options:

--remote-debugging-port=9222

Or run chrome (without chromedriver) locally:

chrome --headless --remote-debugging-port=9222 --disable-gpu https://www.google.com

Then open a new chrome (or tab) and go to http://localhost:9222/

You'll get a link to open your page - click on that you'll get devtools for that remote instance: Chrome remote debug

Related