Can I run the selenium web driver (Firefox) without a graphical interface?

We are considering upgrading our production server from Ubuntu- desktop 10.04 to Ubuntu- server 12.04.

We have various services running on our current desktop OS such as Selenium Web Driver. My question is, is it possible to run Selenium Web Driver from a cli based system?

My immediate thought is that it cannot, because it depends on Firefox, but I would like someone to prove that I'm wrong!

+80
ubuntu selenium webdriver
May 01 '12 at 2:59
source share
8 answers

What you are looking for is a headless-browser .

Yes, you can run Selenium on Firefox without any problems. Below is the post .

Below are brief steps to configure Xvfb

#install Xvfb sudo apt-get install xvfb #set display number to :99 Xvfb :99 -ac & export DISPLAY=:99 #you are now having an X display by Xvfb 
+73
May 01 '12 at 15:02
source share

I easily managed to hide the browser window.

Just install PhantomJS . Then change this line:

 driver = webdriver.Firefox() 

at

 driver = webdriver.PhantomJS() 

The rest of the code does not need to be changed and the browser does not open. For debugging purposes, use driver.save_screenshot('screen.png') at different stages of your code, or just continue to use the Firefox web editor in development.

+15
May 27 '14 at 20:12
source share

If you need browser support without a headset, then you can take a different approach.

https://github.com/detro/ghostdriver

This was announced during the Selenian Conference, and is still under development. It uses PhantomJS as a browser and is much better than HTMLUnitDriver, there are no screenshots yet, but since it is still under active development.

+10
May 2 '12 at 23:02
source share

Yes. You can use HTMLUnitDriver instead of FirefoxDriver when running webdriver. This is a painless browser setting. Details can be found here .

+7
May 01 '12 at 3:01 a.m.
source share

It is optional to use pyvirtualdisplay as follows:

 from pyvirtualdisplay import Display display = Display(visible=0, size=[800, 600]) display.start() #do selenium job here display.close() 

Shorter version:

 with Display() as display: # selenium job here 

This is usually python encapsulation from xvfb and more convenient.

By the way, although PhantomJS is a PhantomJS browser and the window will not open if you use it, it seems that PhantomJS still needs a gui environment.

I got error code -6 when instead of Firefox() instead of Firefox() I use PhantomJS() in headless mode (console with a loopback connected). However, everything is fine in the desktop environment.

+4
Jun 29 '17 at 3:29 on
source share

Another option is GhostDriver, which is now officially supported by WebDriver: Actual Ghostdriver performance boost

+2
Feb 05 '13 at 12:27
source share

Keep in mind that the HtmlUnitDriver web client is single-threaded, and Ghostdriver is only 40% of the features that WebDriver should have.

However, Ghostdriver works correctly for tests, and I am having problems connecting it to the WebDriver hub.

+1
Aug 07 2018-12-12T00:
source share

UPDATE: You will no longer need XVFB to run Firefox. Firefox v55 on Linux and Firefox v56 on Windows / Mac now supports silent execution.

I added some practical documentation here:

https://developer.mozilla.org/en-US/Firefox/Headless_mode#Selenium_in_Java

0
Oct. 20 '17 at 3:00
source share



All Articles