本文介绍了无法关闭Selenium / Firefox中的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用Selenium时,我期待在Firefox中禁用图片。它应该是一个简单的更新Firefox的偏好,这是记录在



然而,当我运行,图像显示,并且当我输入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)

作为参考,这个代码完美的另一个改变首选例如使用 firefox_profile.set_preference(permissions.default.stylesheet,2)行关闭csv文件。我可以告诉csv设置和图像之间的唯一区别是行: permissions.default.image 已经存在about:config(即没有我设置它) ,但是 permissions.default.stylesheet 行不。 ...似乎我可以添加新的行与我想要的价值,但不能改变现有的(或者它是在我输入我的价值后,由Selenium beein塞满了)。

解决方案

据我所知,这个问题与下面的Firefox问题有关:






这意味着被冻结,无法更改,也不会执行任何操作。


$ b

替代方案:


  • 使用扩展程序

  • 切换到 Chrome


I am looking to disable images in Firefox when using Selenium. It should be a simple update of the preferences in firefox, which is documented on the instructions on Disable images in Selenium Python

However when i run, images display, and when i enter about:config, the value for permissions.default.image is still 1, rather than 2 which i have tried setting it to.

My code (written in Python) is:

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)

For reference, this code works perfect with another change to preference e.g. turning off csv files with the line firefox_profile.set_preference("permissions.default.stylesheet",2). The only difference i can tell between the csv setting and the image one, is that the line permissions.default.image already exists in about:config (i.e. without me setting it), however the line permissions.default.stylesheet does not. ... it seems that i can add new lines in with the value i want, but not change an existing one (or it is beein over-ridden by Selenium after i enter my value).

解决方案

From what I understand, this problem is related to the following Firefox issues:

That means that permissions.default.image is frozen, cannot be changed and does nothing.


Alternatives:

这篇关于无法关闭Selenium / Firefox中的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 10:40