0
votes

Running latest version of all features (chrome version 66, selenium version 3.12, chromedriver version 2.39, python version 3.6.5)

I have tried all of the solutions that I have found online but nothing seems to be working. I have automated something using Selenium for Chrome and it does exactly what I need it to do.

The last thing I need to to is hide the browser because I do not need to see the UI. I have attempted to make the browser headless using the following code but when I do the program crashes.

I have also tried to alter the window size to 0x0 and even tried the command: options.set_headless(headless=True) instead but nothing seems to work.

NOTE: I am running on Windows and have also tried with the command:

options.add_argument('--disable-gpu')
4
Please, provide an error output or what are you seeing during run? Add an example of your code to be sure that no typos are there. - Alex Makarenko

4 Answers

0
votes

Try to move browser over the monitor

driver = webdriver.Chrome()
driver.set_window_position(-2000,0) # if -20000 don't help put -10000
0
votes

What is happening when you run, does it produce any error or just run as if you hadn't even added the headless argument?

Here's what I do for mine to run headlessly -

from selenium import webdriver

options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--disable-gpu')
selenium_chrome_driver_path = "blah blah my path is here"

my_driver = webdriver.Chrome(chrome_options = options, executable_path = selenium_chrome_driver_path)

I'm running this code with python 3.6 with up to date selenium drivers on Windows 8 (unfortunately)

0
votes

Got the solutions after combining a few sources. It seems that the libraries get often updated and eventually it becomes deprecated. Atm this one worked for me in Windows, using Python 3.4:

from selenium import webdriver 

options = webdriver.ChromeOptions()
options.headless = True
driver = webdriver.Chrome(executable_path="C:/Users/Admin/Documents/chromedriver_win32/chromedriver", options=options)
-1
votes

Try to use user agent in chrome_options

    ua = UserAgent()
    userAgent = ua.random
    print(userAgent)
    chrome_options.add_argument('user-agent={userAgent}')