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

前端 未结 5 1149
遇见更好的自我
遇见更好的自我 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:55

    Assuming you want to do this in Python, you can add a parameter to chromeOptions so that it won't enable these switches (a bit confusing, but ok).

    Given that you want to remove the following switches:

    --disable-hang-monitor
    --disable-prompt-on-repost
    --disable-background-networking
    --disable-sync
    --disable-translate
    --disable-web-resources
    --disable-client-side-phishing-detection
    --disable-component-update
    --disable-default-apps
    --disable-zero-browsers-open-for-tests
    

    You would set up your Chrome driver like so:

    from selenium import webdriver
    
    chromeOptions = webdriver.ChromeOptions()
    chromeOptions.add_experimental_option(
        'excludeSwitches',
        ['disable-hang-monitor',
         'disable-prompt-on-repost',
         'disable-background-networking',
         'disable-sync',
         'disable-translate',
         'disable-web-resources',
         'disable-client-side-phishing-detection',
         'disable-component-update',
         'disable-default-apps',
         'disable-zero-browsers-open-for-tests'])
    
    chromeDriver = webdriver.Chrome(chrome_options=chromeOptions)
    

提交回复
热议问题