Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do not want the Images to load and CSS to render on Firefox in Selenium WebDriver - Python

I am using Selenium 2 with python bindings to fetch some data from our partner's site. But on an average it's taking me around 13 secs to perform this operation.

I was looking for a way to disable the images css and flash etc.

I am using Firefox 3.6 and also using pyvirtualdisplay to to prevent opening of firefox window. Any other optimization to speed up firefox will be also helpful.
I have already tried network.http.* options but does not help much.

And also set the permissions.default.image = 2

like image 468
Anupam Saini Avatar asked Aug 23 '11 08:08

Anupam Saini


People also ask

Which property should be set to run Firefox browser in selenium?

Generally to run tests on our local machine, we will just specify as WebDriver driver = new FirefoxDriver(); to run on Firefox browser. System. setProperty("webdriver. gecko.

How does selenium save images in python?

We can download images with Selenium webdriver in Python. First of all, we shall identify the image that we want to download with the help of the locators like id, class, xpath, and so on. We shall use the open method for opening the file in write and binary mode (is represented by wb).


1 Answers

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.

like image 114
Anupam Saini Avatar answered Sep 17 '22 11:09

Anupam Saini