Search code examples
pythonseleniumwindows-10headlessgoogle-chrome-headless

Chrome headless is throwing nosuchelements


Chrome headless is throwing nosuchelements and timeout exception for all the scripts in my suite when running on windows 10, when running the same script by commenting the piece of code that set the chrome options to headless, the script is running successfully. Also, the script is running successfully on Mac os with headless chrome.

Other details Platform: windows 10 Chrome version: 74 Scripts written using selenium and python

Kindly let me know if any further details required, Thanks in advance.


Solution

  • In case of headless browser you have to set the window size to fire on event.Because headless browser can't recognise where to click without window size.Hope it will work.Give it a try.

    options = webdriver.ChromeOptions()
    options.add_argument('--headless')
    options.add_argument('--disable-gpu')
    options.add_argument('window-size=1920x1080');