Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firefox - hide browser frame with Selenium

I'm trying to figure out how to hide the border (including the address bar, tabs, title bar... everything that isn't the browser viewport) of my Firefox instance instantiated by Selenium.

If there's some way to have it use a userChrome.css, that would be straightforward enough. I've tried loading a profile folder that included a userChrome.css using this answer as a guide, but it seemed to ignore the styles. I've also looked through Firefox's about:config to see if there's some preference that would hide the frame of the window, but I haven't found anything yet.

Any solution that allows me to hide all or some of these elements when creating the instance with Selenium would be helpful. I know it's silly, but that's how it goes sometimes, you know?

-edit-

I don't think the title bar needs to be hidden. But everything else should be hidden.

-another edit to clarify a few things-

I mentioned kiosk mode in the comments as an example of the sort of thing I'm going for. Kiosk mode isn't exactly what I'm looking for, though. The windows aren't meant to be fullscreen, but they should still lack the elements of a common browser window. Think of it as like an Electron app. Out of the box, Electron lacks an address bar, tabs, etc. That's basically what we have for our app, but it's with regular-old Firefox. Again, whether these elements are displayed or not doesn't typically impact the test, but we want them hidden anyway.

Finally, I a friend of mine tried achieving this goal using a userChrome.css wrapped in a Firefox profile and was able to get Selenium to use the userChrome. So perhaps I need to figure out what I'm doing wrong. The biggest difference between how he did it and how I'm doing it is I must use a remote web driver for testing. But even still, it should be able to load the userChrome.css file. I'll try to update this question with more details as I fiddle with it some more.

-edit-

I think the reason userChrome isn't working when specifying a profile is because of the version(s) of Selenium/Geckodriver/Firefox being used.

The geckodriver version I started with was 0.15. 0.17 behaved exactly the same. 0.18 didn't respect the profile I passed along to it at all and instead had Firefox open the profile selection window (not very useful, but I was able to at least select the correct profile and see the userChrome.css get applied). 0.24 is no different.

Firefox is 52.9.0. Not much I can do about that.

We're using selenium (standalone) server 3.8.1. Switching out for 3.141.59 Didn't change anything.

Unless there's a version combination that will work with Firefox 52, I think the only thing I can do is wait until there's an update.

like image 410
CoryCoolguy Avatar asked May 17 '19 18:05

CoryCoolguy


Video Answer


2 Answers

At last I have figured it out. In order to get Selenium to use my custom profile, I needed to do the following:

FirefoxProfile profile = new FirefoxProfile(new File(path_to_profile));
FirefoxOptions options = new FirefoxOptions().setProfile(profile);
RemoteWebDriver driver = new RemoteWebDriver(options.toCapabilities());
driver.get(url_of_webpage);

Thanks to avinesh09 on Github for the info I needed to solve the problem. It's so simple, but this has to be the only way that I neglected to try to load the profile.

like image 112
CoryCoolguy Avatar answered Oct 06 '22 07:10

CoryCoolguy


If fullscreen (kiosk) mode is what you ask for (as then all you see is the viewport) it is as simple as:

driver.manage().window().fullscreen();

It is the same user experience as pressing "F11" in your browser.

like image 43
Moro Avatar answered Oct 06 '22 08:10

Moro