当前位置: 首页 > 知识库问答 >
问题:

Splinter Selenium Phantomjs驱动程序实例化失败

华景同
2023-03-14

我正在尝试使用Python Splinter Selenium PhantomJS进行基本测试,但我无法启动phantomjs浏览器。(Chrome

from splinter import Browser

b = Browser('phantomjs')

我得到一个错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/splinter/browser.py", line 63, in Browser
    return driver(*args, **kwargs)
  File "/Library/Python/2.7/site-packages/splinter/driver/webdriver/phantomjs.py", line 32, in __init__
    self.driver = PhantomJS(desired_capabilities=capabilities, **kwargs)
  File "/Library/Python/2.7/site-packages/selenium/webdriver/phantomjs/webdriver.py", line 56, in __init__
    desired_capabilities=desired_capabilities)
  File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 87, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 141, in start_session
    'desiredCapabilities': desired_capabilities,
  File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 199, in execute
    response = self.command_executor.execute(driver_command, params)
  File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/remote_connection.py", line 395, in execute
    return self._request(command_info[0], url, body=data)
  File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/remote_connection.py", line 463, in _request
    resp = opener.open(request, timeout=self._timeout)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 431, in open
    response = self._open(req, data)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 449, in _open
    '_open', req)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 409, in _call_chain
    result = func(*args)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1227, in http_open
    return self.do_open(httplib.HTTPConnection, req)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1197, in do_open
    raise URLError(err)
urllib2.URLError: <urlopen error [Errno 8] nodename nor servname provided, or not known>

此外,当我跑步时:

from selenium import webdriver

d = webdriver.PhantomJS()

我基本上得到了同样的错误。

看起来PhantomJS正在使用远程驱动程序连接到远程服务器,但splinter没有启动selenium(?)PhantomJS要连接到的服务器。我不介意进入splinter(?)的源代码为了让这一切顺利进行,我们做了一些改变。然而,我无法确定什么能解决这个问题。

或者,我需要手动启动PhantomJS连接到的服务器吗?

(作为参考,Ruby Cucumber Capybara Poltergeist在我的盒子上效果很好。)这是我的软件的配置。

$ python --version
Python 2.7.10

$ pip show splinter | grep Version
Metadata-Version: 1.1
Version: 0.7.3

$ pip show selenium | grep Version
Metadata-Version: 2.0
Version: 2.47.3

$ phantomjs -v
2.0.0

$ sw_vers
ProductName:    Mac OS X
ProductVersion: 10.10.5
BuildVersion:   14F27

共有2个答案

司寇正志
2023-03-14

我也有同样的错误。然后检查我的/etc/hosts并删除不必要的localhost别名。所有的工作。检查您的/etc/hosts

尹冠宇
2023-03-14

只想分享一下phantomjssplinter在我的机器上可以很好地使用以下配置:

~ $ python --version
Python 2.7.11

~ $ pip show splinter | grep Version
Metadata-Version: 1.1
Version: 0.7.3

~ $ pip show selenium | grep Version
Metadata-Version: 2.0
Version: 2.47.3

~ $ phantomjs -v
2.0.0

~ $ sw_vers
ProductName:    Mac OS X
ProductVersion: 10.11
BuildVersion:   15A284
 类似资料:
  • 有人知道是什么引起的吗?我正在使用Springsource工具套件开发我的应用程序。postgres驱动程序位于web-inf/lib/postgresql-9.1-902.jdbc4.jar下 非常感谢任何帮助!谢谢!

  • 我在通过springboot应用程序连接到oracle db时出现异常。但是我可以使用sql Developer连接到这个数据库。 我使用HikariCP连接数据库

  • 我按照中的说明为MongoDB C驱动程序(版本1.9.2)构建静态库http://mongoc.org/libmongoc/current/installing.html。它安装正确,并且可以构建示例,如 接下来,我想要一个mongcxx静态库。我在Ubuntu 16.04上按照这里的指定执行了以下步骤:https://mongodb.github.io/mongo-cxx-driver/mon

  • 我有一个Spring应用程序,在IDE和本地mariadb中运行良好,在POM中使用mariadb 2.7.4,如下所示,但我在Ubuntu上运行它时出现了第二个错误。我已经删除了mysql连接器,但仍然存在问题。为什么会出现差异和问题? 原因:组织。springframework。豆。BeanInstationException:未能实例化[com.zaxxer.hikari.HikariDat

  • 初始化 Lotus 驱动程序 当安装 Lotus 数据库的驱动程序时,设置程序会在引擎的 Windows 注册表和 ISAM 格式子键写入一些缺省值。不要直接修改这些设置;请使用应用程序的设置程序来添加、删除、或更改这些设置。下面部分描述 Lotus 数据库驱动程序的初始化和 ISAM Format 设置。 Lotus 初始化设置 Jet\3.5\Engines\Lotus 文件夹包含用来访问外部

  • 本文向大家介绍Java加载JDBC驱动程序实例详解,包括了Java加载JDBC驱动程序实例详解的使用技巧和注意事项,需要的朋友参考一下 本文实例说明了Java加载JDBC驱动程序的方法,运行本文实例代码后,如果连接成功就会显示如下一条语句:sun.jdbc.odbc.JdbcOdbcDriver@6ec12,如果连接不成功,则显示加载数据库驱动程序出现异常。 Java加载JDBC的实现方法: 通过