1

From what I have read, headless and non-headless should be able to read a website exactly the same. However, when I run my script in headless it fails because it can't find certain elements (I'm using xpath). I checked the source code that selenium captures using both options and it's exactly the same. However, elements that I'm using from Inspect Element are not in the source code for either so I'm assuming source code does not matter?

When using headless, selenium cannot find a scroller and a button which I'm trying to interact with.

Error:

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

Options

# I'm using the below to execute the driver.
from webdriver_manager.chrome import ChromeDriverManager

options = Options()
options.add_argument("--headless")
#options.add_argument("window-size=1400,600") I've tried with this as well
options.add_argument("User-Agent': 'USER_AGENT = User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36'")
driver = webdriver.Chrome(ChromeDriverManager().install(), options=options)

driver.get("https://website.com")

Any advice or suggestions on troubleshooting further?

squidg
  • 451
  • 6
  • 17
  • 1
    How are you launching your webdriver? What are you options? - when you start headless you get a tiny window size. If your applicantion has a responsive design it reorganises elements. If you've not done it already, specify a window size – RichEdwards Aug 02 '20 at 09:41
  • @RichEdwards I have updated my original post to include some of the code. I've tired specifying a window size (shown above) and it still didn't work unless I did it wrong? – squidg Aug 02 '20 at 13:09

0 Answers0