PhantomjsDriver在Windows和Linux上均不起作用 [英] PhantomjsDriver not working on both Windows and Linux

查看:305
本文介绍了PhantomjsDriver在Windows和Linux上均不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Selenium Webdriver从站点获取一些信息的应用程序. FirefoxDriver和ChromeDriver可以很好地工作,但是当我尝试切换到PhantomJSDriver时,遇到了一些困难.

I have an application that uses Selenium Webdriver to get some information from a site. It works fine with FirefoxDriver and ChromeDriver, but when I tried to switch to PhantomJSDriver, I encountered some difficulties.

  1. 在Windows计算机上,它可以正常启动,然后立即开始一遍又一遍地吐出以下几行:

2014年1月5日晚上7:28:43 org.apache.http.impl.client.DefaultRequestDirector tryEx 兴高采烈 信息:处理请求时捕获到I/O异常(org.apache.http.NoHttpResponseException):目标服务器未能响应

Jan 05, 2014 7:28:43 PM org.apache.http.impl.client.DefaultRequestDirector tryEx ecute INFO: I/O exception (org.apache.http.NoHttpResponseException) caught when processing request: The target server failed to respond

此过程可能会重复几百次,持续约10分钟,直到最终加载页面为止;有时甚至根本无法加载它.

This is repeated probably several hundred times for about 10 minutes until it finally loads the page; sometimes it doesn't even manage to load it at all.

  1. 在Linux计算机上,它尝试启动,然后返回以下内容:

线程"thread1"中的异常 org.openqa.selenium.remote.UnreachableBrowserException:无法 开始一个新的会话.可能的原因是遥控器的地址无效 服务器或浏览器启动失败.构建信息:版本:未知", 修订:'未知',时间:'未知'系统信息:主机:'pangolin', ip:'128.238.32.20',操作系统名称:'Linux',os.arch:'amd64',os.version: '2.6.32-39-generic',java.version:'1.7.0'驱动程序信息: driver.version:PhantomJSDriver 在org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:548) 在org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:216) 在org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:111) 在org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:115) 在org.openqa.selenium.phantomjs.PhantomJSDriver.(PhantomJSDriver.java:107) 在org.openqa.selenium.phantomjs.PhantomJSDriver.(PhantomJSDriver.java:96) 原因:org.openqa.selenium.WebDriverException:等待驱动程序超时 服务器启动.构建信息:版本:未知",修订版:未知", 时间:未知"系统信息:主机:"pangolin",ip:"128.238.32.20", os.name:'Linux',os.arch:'amd64',os.version:'2.6.32-39-generic', java.version:'1.7.0'驱动程序信息:driver.version:PhantomJSDriver 在org.openqa.selenium.remote.service.DriverService.start(DriverService.java:165) 在org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:62) 在org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:527) ... 7更多原因:org.openqa.selenium.net.UrlChecker $ TimeoutException:等待超时 为[http://localhost:16050/status]在20002毫秒后可用 在org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:104) 在org.openqa.selenium.remote.service.DriverService.start(DriverService.java:163) ... 9更多原因:com.google.common.util.concurrent.UncheckedTimeoutException: java.util.concurrent.TimeoutException 在com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:143) 在org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:79) ... 10更多原因:java.util.concurrent.TimeoutException 在java.util.concurrent.FutureTask $ Sync.innerGet(FutureTask.java:258) 在java.util.concurrent.FutureTask.get(FutureTask.java:119) 在com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:130) ...还有11个

Exception in thread "thread1" org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure. Build info: version: 'unknown', revision: 'unknown', time: 'unknown' System info: host: 'pangolin', ip: '128.238.32.20', os.name: 'Linux', os.arch: 'amd64', os.version: '2.6.32-39-generic', java.version: '1.7.0' Driver info: driver.version: PhantomJSDriver at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:548) at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:216) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:111) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:115) at org.openqa.selenium.phantomjs.PhantomJSDriver.(PhantomJSDriver.java:107) at org.openqa.selenium.phantomjs.PhantomJSDriver.(PhantomJSDriver.java:96) Caused by: org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start. Build info: version: 'unknown', revision: 'unknown', time: 'unknown' System info: host: 'pangolin', ip: '128.238.32.20', os.name: 'Linux', os.arch: 'amd64', os.version: '2.6.32-39-generic', java.version: '1.7.0' Driver info: driver.version: PhantomJSDriver at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:165) at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:62) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:527) ... 7 more Caused by: org.openqa.selenium.net.UrlChecker$TimeoutException: Timed out waiting for [http://localhost:16050/status] to be available after 20002 ms at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:104) at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:163) ... 9 more Caused by: com.google.common.util.concurrent.UncheckedTimeoutException: java.util.concurrent.TimeoutException at com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:143) at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:79) ... 10 more Caused by: java.util.concurrent.TimeoutException at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:258) at java.util.concurrent.FutureTask.get(FutureTask.java:119) at com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:130) ... 11 more

我做错了什么?我已经阅读了很多有关Phantomjs如何比其他驱动程序快得多的信息,并且确实想使用它,但是如果加载每个页面需要10分钟,那显然是不可行的.

What am I doing wrong? I've read a lot about how Phantomjs is so much faster than the other drivers, and would really like to use it, but if it takes 10 minutes to load each page, that's obviously not feasible.

我正在运行Selenium WebDriver 2.38.0版和Phantomjs 1.9.2版.

I am running Selenium WebDriver version 2.38.0 and Phantomjs version 1.9.2.

非常感谢您, bsg

Thank you very much in advance, bsg

编辑 只是为了澄清,我认为这与我的代码无关.我在下面尝试启动PhantomJS驱动程序的行上抛出了Linux上的错误.

EDIT Just to clarify, I don't think this has anything to do with my code; the errors on Linux are being thrown on the line where I try to start the PhantomJS driver, below.

   DesiredCapabilities caps = new DesiredCapabilities();
    caps.setJavascriptEnabled(true);                       
    caps.setCapability(
        PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
        phantombinary//"/home/p/phantomjs-1.9.2-linux-x86_64/bin/phantomjs"
    );

    // Launch driver (will take care and ownership of the phantomjs process)
     WebDriver driver = new PhantomJSDriver(caps);
    System.out.println("starting driver");

推荐答案

如果在Linux上仍然无法使用,请尝试以下代码,在Mac上也可以使用.

If it is still not working for you on Linux, try below piece of code, it is working for me on Mac.

capabilities.setCapability("phantomjs.binary.path", "path of phantom binary/phantomjs")

这篇关于PhantomjsDriver在Windows和Linux上均不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆