How to run Selenium Scripts in web servers?

I have written several scripts of selenium [Python] webdriver, and while they work fine on my system, they do not work on my website server. It shows errors with Firefox. Firefox is installed on the server. Web Server - Ubuntu. What do I need to do to run these scripts? Please help, I'm a newbie.

+4
source share
4 answers

Selenium requires a browser to start, and the browser needs some kind of X server to run. There are many types of X servers, and one of them is Xvfb aka X virtual framebuffer, which performs all operations in memory and therefore does not require a screen.

You can find very beautiful examples on Wikipedia .

This is a good example .

+1
source

You probably need to open a browser without a header when executing your scripts on the server.

Here is the Java code for Firefox (Python code should look 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 Firefox is installed on the server with /usr/local/bin/firefox.

0
source

-, , Casper JS, -, .

0

I ended up using pyvirtualdisplaywhich is a Python shell for Xvfb and Xephyr. If someone has the same problems [and I'm sure there will be newbies], you can try THIS . Also you can use xvfbwrapper. Tutorial for xvfbwrapper HERE .

0
source

Source: https://habr.com/ru/post/1525231/


All Articles