6

I have written a few Selenium [Python] webdriver scripts, and while they are running fine on my system, they are not running on my website's server. It is showing errors with Firefox. Firefox is installed on the server. The webserver is Ubuntu. What do I have to do to run those scripts? Please help, I am a newbie.

AndyG
  • 39,700
  • 8
  • 109
  • 143
Saheb
  • 1,666
  • 3
  • 18
  • 24

4 Answers4

2

Selenium requires a running browser and browsers need some kind of X server in order to run. There are many types of X servers and one of them is Xvfb aka X virtual framebuffer that does all the operations in memory and thus requires no screen.

In Wikipedia you could find very nice examples.

This is a nice example too.

Community
  • 1
  • 1
Victor Sigler
  • 23,243
  • 14
  • 88
  • 105
0

You probably need to open the browser headless when executing your scripts on the server.

Here is the Java code for Firefox (Python code should be similar):

import java.io.File;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxBinary;

WebDriver openHeadless() throws Exception
{
    FirefoxBinary binary = new FirefoxBinary(new File("/usr/local/bin/firefox"));
    binary.setEnvironmentProperty("DISPLAY",System.getProperty("lmportal.xvfb.id",":99"));
    return new FirefoxDriver(binary,null); // or 'binary,profile' if you have a profile
}

Make sure that you have Firefox installed on the server at /usr/local/bin/firefox.

barak manos
  • 29,648
  • 10
  • 62
  • 114
0

If you want simply do web browser testing you can use libraries like Casper JS this creates a server side browser for web browser testing, it doesn't need a display driver.

markcial
  • 9,041
  • 4
  • 31
  • 41
0

I ended up using pyvirtualdisplay which is a Python wrapper for Xvfb and Xephyr. If anyone is having same issues [and I am sure newbies will], You can try THIS. Also you can use xvfbwrapper. Tutorial for xvfbwrapper HERE.

Saheb
  • 1,666
  • 3
  • 18
  • 24