java.lang.IllegalStateException:驱动程序可执行文件不存在

时间:2015-03-01 13:34:19

标签: java selenium phantomjs openshift openshift-client-tools

我试图在Openshift服务器上运行phantomjs程序。

但我从one month收到此错误:(

错误:

java.lang.IllegalStateException: The driver executable does not exist: /var/lib/openshift/54eb79134382ecc76d00002b/app-root/data/Phantomjs-1.9.8-linux-x86_64/bin/phantomjs
    com.google.common.base.Preconditions.checkState(Preconditions.java:197)
    org.openqa.selenium.remote.service.DriverService.checkExecutable(DriverService.java:117)
    org.openqa.selenium.phantomjs.PhantomJSDriverService.findPhantomJS(PhantomJSDriverService.java:246)
    org.openqa.selenium.phantomjs.PhantomJSDriverService.createDefaultService(PhantomJSDriverService.java:182)
    org.openqa.selenium.phantomjs.PhantomJSDriver.<init>(PhantomJSDriver.java:99)
    org.apache.jsp.doThatTask_jsp._jspService(doThatTask_jsp.java:87)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

这是我的简单程序:

package com.mySimpleProgram;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriverService;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

public class MainProgram {
    public static void main(String[] args) throws MalformedURLException, InterruptedException{
        DesiredCapabilities caps = new DesiredCapabilities();
        caps.setCapability(
        PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
        System.getenv("OPENSHIFT_DATA_DIR")+"/Phantomjs-1.9.8-linux-x86_64/bin/phantomjs");                  
        WebDriver driver = new PhantomJSDriver(caps);

        driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
        driver.get("https://www.google.com/");

        Thread.sleep(5000);

        out.println(driver.getPageSource());
    }
}

为什么我每次都会在服务器上收到此错误?

3 个答案:

答案 0 :(得分:0)

听起来在传递System.getenv()中的参数时找不到你的驱动程序。仔细检查该位置并确保驱动程序可执行文件存在。

答案 1 :(得分:0)

检查您是否有权阅读/var/lib/openshift/54eb79134382ecc76d00002b/app-root/data/Phantomjs-1.9.8-linux-x86_64/bin/phantomjs目录

答案 2 :(得分:0)

试试这段代码吧,为我工作:

DesiredCapabilities caps = new DesiredCapabilities();
    caps.setJavascriptEnabled(true);

    caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, "D:\\phantomjs-2.0.0-windows\\bin\\phantomjs.exe");

    WebDriver driver = new PhantomJSDriver(caps);
    driver.manage().timeouts().pageLoadTimeout(2000, TimeUnit.SECONDS);


    driver.get("https://github.com/detro/ghostdriver");

    System.out.println(driver.getTitle());