相关疑难解决方法(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:如何使用firefox和python禁用图像加载?

我读过类似的问题,其中一个应该是答案,但是当我尝试它时,它只给出了部分解决方案.

我指的是问题:在Selenium Python中禁用图像

我的问题是我尝试了这个解决方案并且一些图像没有出现,但图像来自:

<img href="www.xxx.png"> 
Run Code Online (Sandbox Code Playgroud)

正在加载.有没有办法告诉firefox/selenium不要得到它?如果没有,有没有办法从我回来的dom元素中丢弃它,通过

self._browser.get(url)
content=self._browser.page_source
Run Code Online (Sandbox Code Playgroud)

例如,通过在dom树上做某种查找替换?

浏览器配置与上一个问题的浏览器相同:

    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)
Run Code Online (Sandbox Code Playgroud)

- - - - - - - - - - - - - - - - - - -更正 - - - - - - -------------------------

我继续挖掘,我学到的是那个,
如果我检查文本文件,selenium/firefox组合做了我看到它,它没有带来图像,然后保持链接.

但当我这样做时:

self._browser.save_screenshot("info.png") 
Run Code Online (Sandbox Code Playgroud)

我有一个24兆的文件加载了所有的img链接.
有人能解释一下这件事吗?
谢谢

python firefox selenium selenium-webdriver

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

Selenium:不要等待异步资源

Selenium在继续执行新页面之前等待异步资源调用.

防爆.

<script src="https://apis.google.com/js/platform.js" async defer></script>
Run Code Online (Sandbox Code Playgroud)

在具有许多外部api的网站上(例如来自G +,Facebook和Twitter的Google Analytics和共享按钮).Selenium花费更多时间等待异步调用,而不是运行测试.

反正是否有禁用此行为,以便selenium不等待异步外部api调用?

python selenium unit-testing selenium-webdriver

6
推荐指数
1
解决办法
1879
查看次数

无法在Selenium/Firefox中关闭图像

我想在使用Selenium时在Firefox中禁用图像.它应该是firefox中首选项的简单更新,它在Selenium Python中禁用图像的说明中有记录

但是,当我运行时,图像显示,当我输入about:config时,值permissions.default.image仍为1,而不是2,我尝试将其设置为.

我的代码(用Python编写)是:

from selenium import webdriver
firefox_profile = webdriver.FirefoxProfile()
firefox_profile.set_preference("permissions.default.image", 2)
driver = webdriver.Firefox(firefox_profile)
driver.get(web_address)
Run Code Online (Sandbox Code Playgroud)

作为参考,此代码适用于对首选项的另一个更改,例如使用该行关闭csv文件firefox_profile.set_preference("permissions.default.stylesheet",2).我可以在csv设置和图像之间区分的唯一区别是,该行permissions.default.image已经存在于about:config(即没有我设置它),但是行permissions.default.stylesheet没有....似乎我可以使用我想要的值添加新行,但不能更改现有的行(或者在输入我的值后,它会被Selenium覆盖).

python firefox selenium selenium-webdriver

5
推荐指数
1
解决办法
4124
查看次数