Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't turn off images in Selenium / Firefox

I am looking to disable images in Firefox when using Selenium. It should be a simple update of the preferences in firefox, which is documented on the instructions on Disable images in Selenium Python

However when i run, images display, and when i enter about:config, the value for permissions.default.image is still 1, rather than 2 which i have tried setting it to.

My code (written in Python) is:

from selenium import webdriver
firefox_profile = webdriver.FirefoxProfile()
firefox_profile.set_preference("permissions.default.image", 2)
driver = webdriver.Firefox(firefox_profile)
driver.get(web_address)

For reference, this code works perfect with another change to preference e.g. turning off csv files with the line firefox_profile.set_preference("permissions.default.stylesheet",2). The only difference i can tell between the csv setting and the image one, is that the line permissions.default.image already exists in about:config (i.e. without me setting it), however the line permissions.default.stylesheet does not. ... it seems that i can add new lines in with the value i want, but not change an existing one (or it is beein over-ridden by Selenium after i enter my value).

like image 635
kyrenia Avatar asked Jul 22 '15 18:07

kyrenia


2 Answers

From what I understand, this problem is related to the following Firefox issues:

  • Remove "Load images automatically" checkbox from Prefs
  • Get rid of options that kill our product

That means that permissions.default.image is frozen, cannot be changed and does nothing.


Alternatives:

  • use Image Block extension
  • switch to Chrome (Disable images in Selenium ChromeDriver)
like image 107
alecxe Avatar answered Oct 12 '22 05:10

alecxe


I had this problem. the solution is bellow in 3 steps. 1- creating new profile for Firefox. in Windows completely close Firefox. press (Window+R) , write firefox.exe -p then press enter and create a new profile. 2-open Firefox with the created profile then open about:config in navigation bar and find permissions.default.image and make it's number 2. 3-change your code like bellow

ProfilesIni profile = new ProfilesIni();
FirefoxProfile myprofile = profile.getProfile("your_profile_name");
WebDriver driver = new FirefoxDriver(myprofile);
like image 44
Ario Avatar answered Oct 12 '22 06:10

Ario