Panshul
Panshul

Reputation: 1084

How to disable Flash in selenium remote webdriver

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.

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.

I tried to to disable the JavaScript by:

WebDriver driver = new FirefoxDriver();
((DesiredCapabilities) driver.getCapabilities()).setJavascriptEnabled(false);

I also tried:

DesiredCapabilities caps = new DesiredCapabilities();
caps.setJavascriptEnabled(false);
WebDriver driver = new FireFoxDriver(caps);

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>

but still all the Javascript is executing on the pages the driver loads and the Flash is also loading.

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

Thank you for the help.

Upvotes: 9

Views: 4883

Answers (3)

Wolf
Wolf

Reputation: 912

I had the same problem and needed it to be solved for Chrome. This is how I got it to work:

    ChromeOptions options = new ChromeOptions();
    options.addArguments("--disable-bundled-ppapi-flash");
    WebDriver webDriver = new org.openqa.selenium.chrome.ChromeDriver(options);

Upvotes: 0

Tasawer Khan
Tasawer Khan

Reputation: 6148

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);

Upvotes: 4

Anuragh27crony
Anuragh27crony

Reputation: 2957

though it's already answered question but on different forum... so i will consolidate for you...

I'm not sure if flash objects are loaded by javascript....but if disabling javascript is problem then...

Never disable Javascript for Firefox driver, in case if you want to use it being disabled try with HTMLUNITDRIVER which specially meant for non-javascript pages.

Reason being important parts of firefox driver is implemented in javascript and disabling would have serious concerns.

HtmlUnitDriver on the other hand is fastest and best way for automation tests (splly for pages with no JS)

please check this group discussion https://groups.google.com/forum/?fromgroups=#!topic/webdriver/daLOzCiU_h4%5B1-25%5D

Upvotes: 0

Related Questions