6

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.

CoryCoolguy
  • 1,065
  • 8
  • 18
  • Selenium works within _Viewport_ why are you concerned with the hide the border (including the address bar, tabs, title bar... everything that isn't the browser viewport)? What is your usecase? – undetected Selenium May 17 '19 at 19:27
  • I understand that it does not have any affect at all on actually running the test. The purpose of the test is to test a kiosk-like application. Even though the presence of these elements have absolutely no bearing on whether or not the test will work as expected, it would be nice (if possible) to test the web app in a way that simulates its intended use. The bottom line is this: It's not my idea and I'm just trying to make the higher-ups happy – CoryCoolguy May 17 '19 at 19:41
  • @DebanjanB Firefox does not have a built-in kiosk mode like Chrome has. While Chrome has the `--kiosk` command line argument, Firefox has nothing of the sort. Instead, we use userChrome.css to achieve a similar effect. Using Chrome instead is not an option either. This question is not the same. – CoryCoolguy May 17 '19 at 20:08

2 Answers2

2

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.

CoryCoolguy
  • 1,065
  • 8
  • 18
1

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.

Moro
  • 781
  • 4
  • 14
  • Some of the windows that open are kept small. Apologies for not saying so in the original question. It's a pretty strange setup. – CoryCoolguy May 21 '19 at 12:22
  • If it is a new window and you want it in fullscreen, you can switch to it via handle and send the same command. If that is not the case I would require some more information as I do not completely understand the situation here. – Moro May 21 '19 at 12:45
  • I swear I'm not moving the goal post! I've updated the question with more details. – CoryCoolguy May 21 '19 at 13:44