Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set chrome.prefs with python binding for selenium in chromedriver

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 specific chrome.prefs (for example profile settings such as profile.managed_default_content_settings.images = 2) using the webdriver.Chrome() method?

I already tried it through webdriver.ChromeOptions() without success. In Java there are appropriate functions available to achieve this.

But Python? This is what I am doing currently...

    options = webdriver.ChromeOptions()
    options.add_argument('--allow-running-insecure-content')
    options.add_argument('--disable-web-security')
    options.add_argument('--disk-cache-dir=/var/www/cake2.2.4/app/tmp/cache/selenium-chrome-cache')
    options.add_argument('--no-referrers')
    options.add_argument('--window-size=1003,719')
    options.add_argument('--proxy-server=localhost:8118')
    options.add_argument("'chrome.prefs': {'profile.managed_default_content_settings.images': 2}")


    self.selenium = webdriver.Chrome(executable_path='/usr/local/bin/chromedriver',chrome_options=options)
like image 967
Jabb Avatar asked Mar 01 '13 19:03

Jabb


1 Answers

For anyone who want to disable images in chromedriver, the following code might help you.

from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_experimental_option( "prefs", {'profile.default_content_settings.images': 2})
driver = webdriver.Chrome(chrome_options=chrome_options)
like image 190
Xiong Avatar answered Sep 19 '22 14:09

Xiong