Set chrome.prefs with python binding for selenium in chromedriver

前端 未结 5 1180
我寻月下人不归
我寻月下人不归 2020-12-04 22:37

I have been searching all day for this and it seems that there is no solution currently available from the chromedriver implementation for python.

how do you set spe

5条回答
  •  执笔经年
    2020-12-04 23:41

    Fix:

    There is a solution by avoiding the chromeoptions object and reverting back to the desiredcapabilities dictionary (deprecated). For some reason webdriver.py in the selenium library adds an empty chromeoptions dictionary to the desiredcapabilities dictionary which renders it useless. So you need to uncomment line 54 in webdriver.py

    desired_capabilities.update(options.to_capabilities())
    

    Then use this code to pass all desired capabilities to chromedriver

    CHROME = {
    "browserName": "chrome",
            "version": "",
            "platform": "ANY",
            "javascriptEnabled": True,
            "chrome.prefs": {"profile.managed_default_content_settings.images": 2},
            "proxy": {
                "httpProxy":"localhost:8118",
                "ftpProxy":None,
                "sslProxy":None,
                "noProxy":None,
                "proxyType":"MANUAL",
                "class":"org.openqa.selenium.Proxy",
                "autodetect":False
                },
            "chrome.switches": ["window-size=1003,719", "allow-running-insecure-content", "disable-web-security", "disk-cache-dir=/var/www/cake2.2.4/app/tmp/cache/selenium-chrome-cache", "no-referrers"],
            }
    
    
        self.selenium = webdriver.Chrome(desired_capabilities=CHROME)
    

提交回复
热议问题