相关疑难解决方法(0)

不希望图像加载和CSS在使用Python的Selenium WebDriver测试中在Firefox上呈现

我正在使用Selenium 2和python绑定从我们的合作伙伴网站获取一些数据.但平均而言,我需要大约13秒才能执行此操作.

我正在寻找一种方法来禁用图像css和flash等.

我正在使用Firefox 3.6并使用pyvirtualdisplay来防止打开firefox窗口.任何其他优化加速Firefox也将有所帮助.
我已经尝试过network.http.*选项,但没有多大帮助.

并且还设置了 permissions.default.image = 2

css python firefox selenium-webdriver

32
推荐指数
3
解决办法
2万
查看次数

在Selenium Python中禁用图像

因为Webdriver在进入下一行之前等待整个页面加载,我认为禁用图像,css和javascript会加快速度.

from selenium import webdriver
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)
Run Code Online (Sandbox Code Playgroud)

我从stackoverflow获取代码不希望加载图像和使用Python在Selenium WebDriver测试中在Firefox上渲染CSS

但是当我补充说

driver = webdriver.Firefox()
driver.get("http://www.stackoverflow.com/")
Run Code Online (Sandbox Code Playgroud)

到最后,它仍然加载图像:/

javascript css python selenium selenium-webdriver

11
推荐指数
2
解决办法
1万
查看次数

标签 统计

css ×2

python ×2

selenium-webdriver ×2

firefox ×1

javascript ×1

selenium ×1