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

Python Selenium无法连接到Webdriver Firefox扩展

许出野
2023-03-14

我使用的是Python 2.7、Selenium 2.35和Firefox 22.0。当我这样做时:

from selenium import webdriver

d = webdriver.Firefox()

Firefox浏览器打开并保持打开状态。控制台中引发以下错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "c:\Python27\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 61, in __init__
    desired_capabilities=capabilities)
  File "c:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 72, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "c:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 114, in start_session
    'desiredCapabilities': desired_capabilities,
  File "c:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 165, in execute
    self.error_handler.check_response(response)
  File "c:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 136, in check_response
    raise exception_class(value)
selenium.common.exceptions.WebDriverException: Message: u''

然后我启动了Fiddler并尝试再次初始化webdrive. Firefox对象:

d = wedriver.Firefox()

与上述错误相同。小提琴手显示以下输出:

{"name":"newSession","status":13,"value":{"message":"b is undefined","stackTrace":[{"methodName":"wdSessionStoreService.prototype.extractCapabilitySetting_",
"fileName":"file:///c:/users/username/appdata/local/temp/tmpzqvpr1/extensions/fxdriver@googlecode.com/components/session_store.js",
"lineNumber":7951},{"methodName":"wdSessionStoreService.prototype.createSession",
"fileName":"file:///c:/users/username/appdata/local/temp/tmpzqvpr1/extensions/fxdriver@googlecode.com/components/session_store.js",
"lineNumber":7944},{"methodName":"nsCommandProcessor.prototype.newSession",
"fileName":"file:///c:/users/username/appdata/local/temp/tmpzqvpr1/extensions/fxdriver@googlecode.com/components/command_processor.js",
"lineNumber":10982},{"methodName":"nsCommandProcessor.prototype.execute",
"fileName":"file:///c:/users/username/appdata/local/temp/tmpzqvpr1/extensions/fxdriver@googlecode.com/components/command_processor.js",
"lineNumber":10875},{"methodName":"Dispatcher.executeAs/<",
"fileName":"file:///c:/users/username/appdata/local/temp/tmpzqvpr1/extensions/fxdriver@googlecode.com/components/driver_component.js",
"lineNumber":7750},{"methodName":"Resource.prototype.handle",
"fileName":"file:///c:/users/username/appdata/local/temp/tmpzqvpr1/extensions/fxdriver@googlecode.com/components/driver_component.js",
"lineNumber":7896},{"methodName":"Dispatcher.prototype.dispatch",
"fileName":"file:///c:/users/username/appdata/local/temp/tmpzqvpr1/extensions/fxdriver@googlecode.com/components/driver_component.js","lineNumber":7843},{"methodName":"WebDriverServer/<.handle","fileName":"file:///c:/users/username/appdata/local/temp/tmpzqvpr1/extensions/fxdriver@googlecode.com/components/driver_component.js","lineNumber":10710},{"fileName":"file:///c:/users/username/appdata/local/temp/tmpzqvpr1/extensions/fxdriver@googlecode.com/components/httpd.js","lineNumber":1935},{"methodName":"ServerHandler.prototype.handleResponse","fileName":"file:///c:/users/username/appdata/local/temp/tmpzqvpr1/extensions/fxdriver@googlecode.com/components/httpd.js","lineNumber":2261},{"methodName":"Connection.prototype.process","fileName":"file:///c:/users/username/appdata/local/temp/tmpzqvpr1/extensions/fxdriver@googlecode.com/components/httpd.js","lineNumber":1168},{"methodName":"RequestReader.prototype._handleResponse","fileName":"file:///c:/users/username/appdata/local/temp/tmpzqvpr1/extensions/fxdriver@googlecode.com/components/httpd.js","lineNumber":1616},{"methodName":"RequestReader.prototype._processBody","fileName":"file:///c:/users/username/appdata/local/temp/tmpzqvpr1/extensions/fxdriver@googlecode.com/components/httpd.js","lineNumber":1464},{"methodName":"RequestReader.prototype.onInputStreamReady",
"fileName":"file:///c:/users/username/appdata/local/temp/tmpzqvpr1/extensions/fxdriver@googlecode.com/components/httpd.js","lineNumber":1333}]}}

如果我加载本地主机:57554,我会得到:

httpd.js

If you're seeing this page, httpd.js is up and serving requests! Now set a base path and serve some files!

因此,Webdriver似乎可以正常工作,但由于某些原因,Python无法启动会话。以前有人遇到过这个问题吗?是什么原因导致的?

共有1个答案

丁志勇
2023-03-14

此问题是由HTTP_PROXY环境变量引起的。通过控制面板更改 Windows 设置不会更改环境变量的值。在实例化 Web 驱动程序之前从 Python 环境中删除变量可以解决此问题:

import os

if 'HTTP_PROXY' in os.environ:
    os.environ.pop('HTTP_PROXY')
 类似资料:
  • 问题内容: 我正在尝试使用Ruby on Rails运行Selenium的示例脚本。我必须使用代理运行它。这是我的代码: 我收到以下错误: 有人能帮我吗…?我已经尝试了好几个小时,却找不到问题…真的不知道该怎么办。 环境: Ubuntu 16.04 LTS,Firefox 45.0,rbenv 2.3.1 另一个问题:有人知道Selenium + Ruby on Rails的示例吗?我找不到真正好

  • 我正在尝试连接到MySQL服务器,但出现无法处理的错误。 java.sql.SQLNonTransientConnectionException:无法创建到数据库服务器的连接。尝试重新连接3次。放弃。com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:110)com.mysql.cj.jdbc.excepti

  • 我真的想不通为什么我不能用下面的代码连接到我的Django项目内的JQuery。你能告诉我是什么原因吗?多谢! null null

  • 我正在尝试使用Android studio提供的工具将我的Android应用程序连接到firebase,但我面临着很多麻烦。 我已经尝试更新依赖到最新的最新的谷歌服务,但错误仍然存在,显示的错误是无法解析Android应用模块的Gradle配置。解决分级生成问题和/或重新同步。 分级/应用程序a

  • 我正在开发Selenium,目前我有一个连接到两个运行linux和所有浏览器的虚拟机的集线器。 我能够启动浏览器,直到它突然停止。火狐或任何其他浏览器都不会启动。我得到以下错误。 45000 ms后无法连接到端口7055上的主机127.0.0.1。 我运行Selenium服务器独立2.26与火狐16.0.2. 请帮忙。

  • Q-我安装了git以获取最新版本的Angular。当我尝试运行时 我连接到github 443错误失败 我甚至试过 这使我无法连接,没有错误消息。 我在公司防火墙后面。转到控制面板时,我看不到我的代理详细信息- 我终于做到了。我将更新我所采取的程序,以便只是想编译我所做的所有步骤,以使它正常工作

  • 我试图使用将一些更改推送到github,但一段时间后它显示错误 我刚刚创建了回购协议,已经promise了两次。我通过Mac OS X Yosemite 10.10.2中的家庭WiFi和操作系统连接到互联网。

  • 输入JDBC的用户名:hive2://localhost:10001/default:输入JDBC的密码:hive2:/localhost:10001/default:17/08/19 09:25:14[main]:警告JDBC.hiveConnection:无法连接到localhost:10001无法打开到HS2服务器的连接。请检查服务器URI,如果URI正确,请让管理员检查服务器状态。错误:无