Selenium: How to disable image upload using firefox and python?

I read similar questions, one was supposed to be the answer, but when I tried it, he gave only a partial solution.

I refer to the question: Disable images in Selenium Python

My problem is that I tried this solution and some of the images are not displayed, but the images that come from:

<img href="www.xxx.png"> 

Loading. Is there any way to tell firefox / selenium not to get it? If not, is there any way to drop it from the dom element, which I will return, through

 self._browser.get(url) content=self._browser.page_source 

for example, by doing some replacement on the dom tree?

The browser configuration is the same browser from the previous question:

  firefox_profile = webdriver.FirefoxProfile() # Disable CSS firefox_profile.set_preference('permissions.default.stylesheet', 2) # Disable images firefox_profile.set_preference('permissions.default.image', 2) # Disable Flash firefox_profile.set_preference('dom.ipc.plugins.enabled.libflashplayer.so', 'false') # Set the modified profile while creating the browser object self._browser = webdriver.Firefox(firefox_profile=firefox_profile) 

------------------------------------- CORRECTION --------- --- -------------------------

I kept digging and I found out that,
If I check a text document that the selenium / firefox host I saw this, it did not bring images and was saved then as links.

But when I did:

 self._browser.save_screenshot("info.png") 

I have a 24 megabyte file with all the img links loaded.
Can someone explain this question to me?
Thanks

+5
source share
1 answer

You can disable images using the following code:

 firefox_profile = webdriver.FirefoxProfile() 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) 

if you need to block a specific url ... hm ... I think you need to add a line:

 127.0.0.1 www.someSpecificUrl.com 

to the hosts file before starting the test and delete it after the test is completed.

+3
source

All Articles