Denis Abakumov
Denis Abakumov

Reputation: 422

How to open "about:preferences" in Firefox using java WebDriver

I need to open the Preferences page in Firefox using WebDriver, in order to clear the cache in a browser-specific way.

While investigating the issue, I found a Python solution and tried to translate it in Java, but WebDriver misinterpretes the uri:

driver.get("about:preferences#privacy");

and sends "/about:preferences#privacy" instead which Firefox doesn't know how to open.

I also tried a JavaScript way:

driver.executeScript("window.location.replace('about:preferences#privacy');")
driver.executeScript("window.open('about:preferences#privacy');")

but these are just ignored by the browser.

I assume there MUST be a Java way because this had already been implemented with Python WebDriver (see the first link).

Update: this turned out to be a non-WebDriver issue. In fact this originates in the testing framework that we're using and which is built around Selenium - Quantum Perfecto. The described behavior doesn't happen in pure Selenium. I sent a request to the framework support team to solve the issue in their code.

Upvotes: 0

Views: 510

Answers (2)

azbarcea
azbarcea

Reputation: 3657

An introduction into Custom Firefox Profile for Selenium

You will use it like:

ProfilesIni profile = new ProfilesIni();
FirefoxProfile myprofile = profile.getProfile("<your-profile-name>");
WebDriver driver = new FirefoxDriver(myprofile);

As Mike 'Pomax' Kamermans says, the best would be to create the profiles based on the requirements you have.

If you need to programatically to create the environments, use a configuration management (like Puppet/Chef/Ansible), or even use maven to generate multiple environment.properties that you can use with custom script to configure (or create from scratch) a Firefox profile, which is answered in this thread

Upvotes: 2

Rahul L
Rahul L

Reputation: 4349

You can navigate to "about:preferences#privacy" by using driver.navigate().to();

Tested on the FF-68 , Selenium 4.0.0-alpha-2 (Java Binding)

driver.navigate().to("about:preferences#privacy");

Upvotes: 0

Related Questions