Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 370
Panshul Avatar asked Oct 01 '12 15:10

Panshul


People also ask

How do I stop ads in Selenium?

1) void dismiss() – The dismiss() method clicks on the “Cancel” button as soon as the pop up window appears. 2) void accept() – The accept() method clicks on the “Ok” button as soon as the pop up window appears. 3) String getText() – The getText() method returns the text displayed on the alert box.

How do I turn off WebDriver?

close() closes only the current window on which Selenium is running automated tests. The WebDriver session, however, remains active. On the other hand, the driver. quit() method closes all browser windows and ends the WebDriver session.

How do you check if a Radiobutton is checked or not in Selenium?

Few of these methods are: isSelected(): Checks whether a radio button is selected or not. isDisplayed(): Checks whether a radion button is displayed on the web page or not. isEnabled(): Checks whether a radion button is enabled or not.

What is remote execution in Selenium?

1. Selenium Remote Webdriver : It is an interface which is used to execute the browser automation and to execute assessments in a distributed environment or on a remote computing device. In other words, It is a class which implements the WebDriver interface and this action is performed on the remote server.


1 Answers

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);
like image 108
Tasawer Khan Avatar answered Sep 22 '22 00:09

Tasawer Khan