Apply settings to Selenium's FirefoxDriver

Viewed 35

I am trying to run the org.openqa.selenium.firefox.FirefoxDriver in Java.

I would like to open a browser window without the address bar and other functionalities like page-forward and so on.

Actually I would like to have a plain window with the displayed web content and even disabled context menu.

How to archive that.

I tried with the code:

FirefoxOptions op = new FirefoxOptions()
                .addPreference("browser.startup.page", 1)
                .addPreference("browser.startup.homepage", "https://google.com");

WebDriver driver = new FirefoxDriver();

but could not find any good, easy understandable documentation for preferences or arguments (addArgument(...)).

Could anyone give me a hint here?

These resources also did not give me a good understandable help:
https://developer.mozilla.org/en-US/docs/Web/WebDriver/Capabilities/firefoxOptions
https://searchfox.org/mozilla-central/source/modules/libpref/init/all.js
How to correctly use FirefoxOptions() and its arguments to pass it to the FirefoxDriver() constructor

Other threads I found on the internet are many years old.

As bonus, the same links for Chrome would also be appreciated.

1 Answers

This is a solution what I almost perfectly want. It does not deal with Selenium/Selenide, which is fully ok with me. I made it work nicely with Chrome browser.

See: https://github.com/greyshine/javaspring-embedded-browser Most interesting files are the index.html and BrowserAdaptor.java.

What I still miss:

  • A nice way independent on the OS on how to locate the executable for the browser; see application.properties

  • Firefox does not open with a pure screen but still has tabs and some browser functions. What would be the startup parameters (see application.properties) for firefox to correctly start.

  • Same story for the Edge browser. Startup parameters, etc...

Bringing Selenide into the question was based, that I seen that this must be somehow possible.

Related