Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 加载firefox后Selenium FireFoxDriver配置文件发生更改?_Java_Image_Selenium_Blocking_Selenium Firefoxdriver - Fatal编程技术网

Java 加载firefox后Selenium FireFoxDriver配置文件发生更改?

Java 加载firefox后Selenium FireFoxDriver配置文件发生更改?,java,image,selenium,blocking,selenium-firefoxdriver,Java,Image,Selenium,Blocking,Selenium Firefoxdriver,加载一些网页后如何更改图像阻止?从命令行firefox.exe-p运行firefox 之后,创建一个新的配置文件,设置必要的设置,并始终调用此配置文件 ProfilesIni profile = new ProfilesIni(); FirefoxProfile ffprofile = profile.getProfile("default");//using firefox default profile ffprofile.setPreference("permissions.default

加载一些网页后如何更改图像阻止?

从命令行firefox.exe-p运行firefox

之后,创建一个新的配置文件,设置必要的设置,并始终调用此配置文件

ProfilesIni profile = new ProfilesIni();
FirefoxProfile ffprofile = profile.getProfile("default");//using firefox default profile
ffprofile.setPreference("permissions.default.image", 2); // this make ff to block web page images
WebDriver ff = new FirefoxDriver(ffprofile);    // executing firefox with specified profile 
ff.navigate().to("www.google.com");             // loading web page  



//codes for changing image blocking ???????????

可以通过dev toolbar CLI在飞行中修改首选项,但这可能会带来比加载图像更高的开销。 以下是Python示例:

从selenium导入webdriver
从selenium.webdriver.common.action\u chains导入ActionChains、键
ff=webdriver.Firefox()
ff.get('http/'))
ac=动作链(ff)
#SHIFT+F2打开开发工具工具栏
ac.Keys\U down(Keys.SHIFT)。发送Keys(Keys.F2)。Keys\U up(Keys.SHIFT)。执行()
#用于禁用图像的命令
ac.send_key('pref set permissions.default.image 2')。perform()
ac.send_key(key.ENTER).perform()
#禁用闪存的命令
ac.send_键('pref set plugin.state.flash 0')。perform()
ac.send_key(key.ENTER).perform()
#禁用开发工具工具栏
ac.Keys\U down(Keys.SHIFT)。发送Keys(Keys.F2)。Keys\U up(Keys.SHIFT)。执行()
ac.Keys\U down(Keys.SHIFT)。发送Keys(Keys.F2)。Keys\U up(Keys.SHIFT)。执行()
#重新加载页面以确认没有图像或闪光灯
ff.refresh()

由于dev toolbar CLI不适用于我(因为组合键不能打开CLI),因此以下是我如何更改正在运行的firefox实例的配置文件设置的:

FirefoxProfile ffprofile = profile.getProfile("profileName");
这是C#但是Java中的转换应该不会太难。
其思想是about:config选项卡声明了许多允许更改概要文件设置的Javascript对象,因此我们只需进入该页面并执行一些JS代码

我可以成功加载任何firefox配置文件。但我想在firefox加载后更改配置文件设置。用户可以通过在ff地址栏中输入“about:config”来更改任何配置文件设置。我想以编程方式更改它。这是不可能的。配置文件是在创建Firefox实例之前创建的,无法更改。是。这是不可能改变firefox加载后的“配置文件”,但我想改变“配置文件设置”。请尝试通过在地址栏中输入“about:config”来更改配置文件。然后,您可以更改任何首选项,例如“permission.default.images”来阻止图像。嗨,khostro,您在加载firefox后成功地通过编程更新了配置文件设置吗?
        IWebDriver driver = //your instance
        driver.Navigate().GoToUrl("about:config");
        driver.FindElement(By.Id("warningButton")).Click();
        IJavaScriptExecutor js = (IJavaScriptExecutor)driver;

        js.ExecuteScript("window.Services.prefs.setIntPref('permissions.default.image', " + 2 + ")");