2

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
  • Answer to your second question about hooking into existing browser - fairly sure you cannot. I've seen the question asked before and it's not been done Commented Jul 13, 2020 at 16:46

3 Answers 3

5

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

Sign up to request clarification or add additional context in comments.

3 Comments

does not work, without chromeOptions.add_argument("--headless") the webpage opens up , but with it , it throws the error mentioned in question. Thanks
Run the site manually in headless from or combine the remote debugging port with your option tags : chrome --headless --remote-debugging-port=9222 --disable-gpu https://<yoursite>then open a new chrome and go to 127.0.0.1:9222
I'm running Chromium in headless mode and the window size worked for me. Thanks
0

I had same error. I had solve it by just adding argument: --start-maximized to chrome_options.

Comments

0

Check for the webpage if it contains ad elements overlying your element you want to click. I had the similar problem occuring with an webpage. To solve you have multiple options:

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.