disable image loading for selenium tests

3,134 views
Skip to first unread message

l.arm...@gmail.com

unread,
Sep 10, 2015, 11:02:19 AM9/10/15
to ChromeDriver Users
Hi,
i am trying to stop chrome from loading pictures with something like this:

val chromeOptions = new ChromeOptions()
chromeOptions.setExperimentalOption("prefs", new JSONObject().put("profile.default_content_settings", "2"))

val contentSettings = new util.HashMap[String, Any]()
contentSettings.put("images", 2)
val preferences = new util.HashMap[String, Object]()
preferences.put("profile.default_content_settings", contentSettings)

val caps = DesiredCapabilities.chrome()
caps.setCapability("chrome.prefs", preferences)
new ChromeDriver(caps)

doesnt work ... also tried addArguments and setExperimentalOptions .... nothing seems to help }(_+[~<*=>%ſ]<|…&^<%

HELP ME PLS :-)

sri.sud...@gmail.com

unread,
Sep 11, 2015, 7:32:50 AM9/11/15
to ChromeDriver Users, l.arm...@gmail.com
You can pass profile options through chromeOptions as shown in below java code

Sample Java code:
HashMap<String, Object> images = new HashMap<String, Object>();
images.put("images", 2);

HashMap<String, Object> prefs = new HashMap<String, Object>();
prefs.put("profile.default_content_settings", images);

ChromeOptions options =new ChromeOptions();
options.setExperimentalOption("prefs", prefs);

DesiredCapabilities chromeCaps = DesiredCapabilities.chrome();
chromeCaps.setCapability(ChromeOptions.CAPABILITY, options);

ChromeDriver cd = new ChromeDriver(chromeCaps);
cd.get("http://google.com");

Linus Armakola

unread,
Sep 16, 2015, 5:07:58 AM9/16/15
to sri.sud...@gmail.com, ChromeDriver Users
Thanks a lot it worked and i am i bit closer to a solution :-)

Linus
Message has been deleted

goyal....@gmail.com

unread,
Feb 23, 2016, 9:06:28 AM2/23/16
to ChromeDriver Users, sri.sud...@gmail.com, l.arm...@gmail.com
The above code is not working for me.. pls help me

gmani...@google.com

unread,
Feb 23, 2016, 6:49:30 PM2/23/16
to ChromeDriver Users, l.arm...@gmail.com, goyal....@gmail.com

Looks like Chrome profile preferences have been changed.

Please use below code :-

        HashMap<String, Object> images = new HashMap<String, Object>(); 
        images.put("images", 2); 

        HashMap<String, Object> prefs = new HashMap<String, Object>(); 
        prefs.put("profile.default_content_setting_values", images);


        ChromeOptions options =new ChromeOptions(); 
        options.setExperimentalOption("prefs", prefs); 

        DesiredCapabilities chromeCaps = DesiredCapabilities.chrome(); 
        chromeCaps.setCapability(ChromeOptions.CAPABILITY, options); 

        ChromeDriver driver = new ChromeDriver(chromeCaps); 
        driver.get("http://google.com/images");

drazen...@gmail.com

unread,
Apr 6, 2016, 7:37:15 AM4/6/16
to ChromeDriver Users, l.arm...@gmail.com, goyal....@gmail.com
Can you tell where I can find the list of Chrome profile preferences?
When did they change the bellow mentioned preference?

gmani...@google.com

unread,
Apr 15, 2016, 5:36:20 PM4/15/16
to ChromeDriver Users, l.arm...@gmail.com, goyal....@gmail.com, drazen...@gmail.com
You can create chrome profile by passing 'user-data-dir' command line switch

ChromeOptions options = new ChromeOptions();
options.addArguments("user-data-dir=/path/to/your/custom/profile");

"Preferences" file will be generated in /path/to/your/custom/profile/Default/

Message has been deleted

dushya...@gmail.com

unread,
Dec 28, 2017, 6:08:54 AM12/28/17
to ChromeDriver Users
On Tuesday, 23 February 2016 19:36:28 UTC+5:30, goyal....@gmail.com wrote:
> The above code is not working for me.. pls help me

HashMap<String, Object> images = new HashMap<String, Object>();
images.put("images", 2);

HashMap<String, Object> prefs = new HashMap<String, Object>();

prefs.put("profile.default_content_setting_values", images);


ChromeOptions chOptions =new ChromeOptions();
chOptions.setExperimentalOption("prefs", prefs);


WebDriver driver = new ChromeDriver(chOptions);
driver.get("http://google.com/images");

Reply all
Reply to author
Forward
0 new messages