how to override default set of chrome command line switches in selenium

前端 未结 5 1146
遇见更好的自我
遇见更好的自我 2021-01-06 09:34

By default, chrome will be run with this command line:

\"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe\"
--disable-hang-monitor
--disable-         


        
5条回答
  •  独厮守ぢ
    2021-01-06 09:51

    The official way to customize the Chrome options from within selenium:

        # renaming import in order to avoid collision with Options for other browsers, so that you can also use e.g.
        # from selenium.webdriver.firefox.options import Options as FirefoxOptions
    
        from selenium.webdriver.chrome.options import Options as ChromeOptions
    
    
        options = ChromeOptions()
        options.add_argument("--headless")
        options.add_argument('--disable-gpu')
        options.add_argument('--disable-dev-shm-usage')
        options.add_argument('--disable-extensions')
        options.add_argument('--no-sandbox')
        options.add_argument('window-size=1920,1080')
    
        # only necessary if you want to use a specific binary location
        # options.binary_location = '/Applications/Chromium.app/Contents/MacOS/Chromium'
    
        driver = webdriver.Chrome(chrome_options=options)
    

提交回复
热议问题