如何在Selenium远程WebDriver中禁用Flash [英] How to disable Flash in selenium remote webdriver
问题描述
使用Selenium Remote WebDriver时如何禁用Flash对象的加载. 如果我也能为普通的网络驱动程序找到解决方案,那将很有帮助.
How do I disable the loading of flash objects when using Selenium Remote WebDriver. It will be helpful if I get a solution for the normal webdriver also.
由于在大多数情况下,Flash对象是由JavaScript加载的 我曾尝试同时禁用WebDriver和远程WebDriver上的javascript,但这不起作用.
Since in most cases the Flash object is loaded by a JavaScript I have tried disabling the javascript on the webdriver and remote webdriver both, but it does not work.
我尝试通过以下方式禁用JavaScript:
I tried to to disable the JavaScript by:
WebDriver driver = new FirefoxDriver();
((DesiredCapabilities) driver.getCapabilities()).setJavascriptEnabled(false);
我也尝试过:
DesiredCapabilities caps = new DesiredCapabilities();
caps.setJavascriptEnabled(false);
WebDriver driver = new FireFoxDriver(caps);
对于远程WebDriver,我尝试过:
For Remote WebDriver i tried:
final DesiredCapabilities firefoxCapability = DesiredCapabilities.firefox();
firefoxCapability.setJavascriptEnabled(false);
new RemoteWebDriver(new URL("http://" + windowsIP + ":4444/wd/hub"), firefoxCapability);
执行上述语句后,远程服务器将显示
After execution of the above statement the remote server displays
Executing: [new session: <platform=ANY, javascriptEnabled=false, browserName=firefox, version=>] at URL:/session>
但是仍然所有Javascript都在驱动程序加载的页面上执行,并且Flash也正在加载.
but still all the Javascript is executing on the pages the driver loads and the Flash is also loading.
请帮助我: 1.如何停止加载闪光灯. 2.在远程驱动程序上需要它,因为我需要在IE,Firefox,Chrome上测试页面.因此,加载前者档案将不起作用
Please help me : 1. how can stop the flash from loading. 2. need it on remote driver as I need to test the pages on IE, Firefox, Chrome. Hence loading the forefox profile will not work
感谢您的帮助.
推荐答案
我在Linux mint上使用了此代码,并且可以正常工作:
I used this code on Linux mint and it works:
FirefoxProfile profile= new FirefoxProfile();
profile.setPreference("plugin.state.flash", 0);
FirefoxDriver driver = new FirefoxDriver(profile);
这篇关于如何在Selenium远程WebDriver中禁用Flash的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!