Do not want the Images to load and CSS to render on Firefox in Selenium WebDriver - Python
I have figured out a way to prevent Firefox from loading CSS, images and Flash.
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
def disableImages(self):
## get the Firefox profile object
firefoxProfile = FirefoxProfile()
## Disable CSS
firefoxProfile.set_preference('permissions.default.stylesheet', 2)
## Disable images
firefoxProfile.set_preference('permissions.default.image', 2)
## Disable Flash
firefoxProfile.set_preference('dom.ipc.plugins.enabled.libflashplayer.so',
'false')
## Set the modified profile while creating the browser object
self.browserHandle = webdriver.Firefox(firefoxProfile)
Thanks again @Simon and @ernie for your suggestions.
Disable images in Selenium Python
UPDATE: The answer might not work any longer since permissions.default.image
became a frozen setting and cannot be changed. Please try with quickjava
extension (link to the answer).
You need to pass firefox_profile
instance to the webdriver
constructor:
from selenium import webdriver
firefox_profile = webdriver.FirefoxProfile()
firefox_profile.set_preference('permissions.default.stylesheet', 2)
firefox_profile.set_preference('permissions.default.image', 2)
firefox_profile.set_preference('dom.ipc.plugins.enabled.libflashplayer.so', 'false')
driver = webdriver.Firefox(firefox_profile=firefox_profile)
driver.get('http://www.stackoverflow.com/')
driver.close()
And this is how it would be displayed:
Can't turn off images in Selenium / Firefox
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)
How to prevent css and img download in selenium
If you check phantomjs API, an option can be passed as:
--load-images=[true|false] load all inlined images (default is true). Also accepted: [yes|no].
However, you cannot block CSS download AFAIK.
Related Topics
How to Shoot a Bullet With Space Bar
Executing Command Using "Su -L" in Ssh Using Python
Using Python 32 Bit in 64Bit Platform
"E: Unable to Locate Package Python-Pip" on Ubuntu 18.04
High Kernel CPU When Running Multiple Python Programs
Multiprocessing Module Showing Memory for Each Child Process Same as Main Process
What Is My Current Desktop Environment
How to Package a Python Daemon with Setuptools
Python Program with Notification in Gnome Shell Doesn't Work
How to Connect to Flask Local Server
Single Quotes Vs. Double Quotes in Python
Gunicorn Command Not Found, But It's in My Requirements.Txt
Matplotlib-Animation "No Moviewriters Available"
Can You Fool Isatty and Log Stdout and Stderr Separately
Why Does Simple Echo in Subprocess Not Working
Can't Install Gcloud on Amazon Linux:Invalid Syntax