Disable chrome window in selenium python

2

I need to deactivate the browser window that opens when the tests are run. I copy the code I use and it should work but it does not:

from selenium.webdriver.chrome.options import Options

class LoginTest(unittest.TestCase):

def test(self):
    options = Options()
    options.add_argument("--headless")
    options.add_argument("--disable-gpu")
    options.add_argument("--no-sandbox")

    driver = webdriver.Chrome(chrome_options=options)

I use:

Python 3.5

Chromedriver 2.35

Google Chrome 64.0.3282.167

Selenium 3.9.0

Any help?

    
asked by Yamila Marucci 20.02.2018 в 21:41
source

1 answer

1

Apparently the options that are passed to Chrome through webdriver should not bring the -- in front. Also, at others places I've seen the options object differently.

Try to do it like in the tutorials I've linked, that is:

from selenium import webdriver

class LoginTest(unittest.TestCase):        
    def test(self):
        options = webdriver.chromeOptions()
        options.add_argument("headless")
        options.add_argument("disable-gpu")
        options.add_argument("no-sandbox")       
        driver = webdriver.Chrome(chrome_options=options)
    
answered by 21.02.2018 / 18:36
source