Reputation: 13
from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--headless")
chrome_options.add_argument('--user-agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36"')
chrome_options.add_argument("--window-size=1920x1080")
chrome_options.add_argument("--disable-extensions")
driver = webdriver.Chrome(chrome_options=chrome_options)
driver.get('https://www.mycarinfo.com.my/Valuation/SearchVehicle?version=free')
Running the code on Windows 7, Python 3.6.4, Selenium 3.9.0, Chromedriver 2.43 The code executes without issue in non-headless mode. In headless mode, executed in Anaconda Prompt, outputs the following error continuously:
Upvotes: 1
Views: 99
Reputation: 2563
Since you're running on windows, you'll need to add the --disable-gpu
argument when using headless. See https://developers.google.com/web/updates/2017/04/headless-chrome
In selenium version 3.9
which you say you're using, you can also use the convenience method set_headless()
which will add both --headless
and --disable-gpu
for you. In newer versions it's a setter options.headless = True
Upvotes: 1