Anupam Saini Anupam Saini - 9 months ago 129
Python Question

Do not want images to load and CSS to render on Firefox in Selenium WebDriver tests with 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

options but does not help much.

And also set the
permissions.default.image = 2


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
    ## Set the modified profile while creating the browser object 
    self.browserHandle = webdriver.Firefox(firefoxProfile)

Thanks again @Simon and @ernie for your suggestions.