如何在Web服务器中运行Selenium脚本?

Sah*_*heb 5 python testing selenium selenium-webdriver

我写了一些Selenium [Python] webdriver脚本,虽然它们在我的系统上运行良好,但它们并没有在我的网站服务器上运行.它显示Firefox的错误.Firefox安装在服务器上.网络服务器是Ubuntu.我该怎么做才能运行这些脚本?请帮忙,我是新手.

bar*_*nos 0

在服务器上执行脚本时,您可能需要打开无头浏览器。

以下是 Firefox 的 Java 代码(Python 代码应该类似):

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
}
Run Code Online (Sandbox Code Playgroud)

确保您已在位于 的服务器上安装了 Firefox /usr/local/bin/firefox