Can't turn off images in Selenium / Firefox
Asked Answered
M

4

6

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).

Mclaren answered 22/7, 2015 at 18:57 Comment(4)
did you also disable flash? firefox_profile.set_preference('dom.ipc.plugins.enabled.libflashplayer.so', 'false')Merridie
Which selenium and which Firefox versions are you using? Thanks.Develop
@Develop Firefox 39, and Salenium 2.46.0. Also, it seems that i can't change default values - i can create the value "permissions.default.image_new" with value 2, but not change "permissions.default.image" from 1 to 2Mclaren
@Mclaren yup, I'm able to reproduce the issue, working on it.Develop
D
8

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

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


Alternatives:

Develop answered 22/7, 2015 at 19:37 Comment(2)
Thanks Alecxe! Followed your advice on using extensions although found QuickJava worked best, as Image Block did not support latest version of firefox. I have shared my code which solves problem in #25214973Mclaren
Setting permissions.default.image works for me on Firefox 66.0.5.Jairia
L
1

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);
Landy answered 29/5, 2016 at 12:44 Comment(0)
R
1

I've created a code sample for disabling images.

#DISABLE IMAGES ON FIREFOX
def disable_images(driver):
    driver.get("about:config")
    driver.find_element("id","warningButton").click()
    searchArea=driver.find_element("id","about-config-search")
    searchArea.send_keys("permissions.default.image")
    editButton=driver.find_element("xpath","/html/body/table/tr[1]/td[2]/button")
    editButton.click()
    editArea=driver.find_element("xpath","/html/body/table/tr[1]/td[1]/form/input")
    editArea.send_keys("2")
    saveButton=driver.find_element("xpath","/html/body/table/tr[1]/td[2]/button")
    saveButton.click()
Responsibility answered 20/8, 2022 at 11:49 Comment(0)
D
1

As of 2023-10, it does work again, though the code has changed a bit since selenium 4:

import shutil

from selenium.webdriver import FirefoxProfile, Firefox
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.firefox.options import Options


profile = FirefoxProfile()
profile.set_preference("permissions.default.image", 2)

options = Options()
options.profile = profile

service = Service(executable_path=shutil.which("geckodriver"))
driver = Firefox(service=service, options=options)
Doridoria answered 17/10, 2023 at 19:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.