Python Selenium无法连接到Webdriver Firefox扩展

增强现实

我正在使用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并尝试再次初始化webdriver.Firefox对象:

d = wedriver.Firefox()

与上述相同的错误。Fiddler显示以下输出:

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

如果我加载,localhost: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无法启动会话。有人以前有过这个问题吗?是什么原因造成的?

增强现实

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

import os

if 'HTTP_PROXY' in os.environ:
    os.environ.pop('HTTP_PROXY')

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Selenium WebDriver Firefox错误-无法连接

Selenium Firefox WebDriver扩展安装

Selenium Firefox无法添加扩展

Selenium Python Firefox WebDriver:无法修改配置文件

Firefox WebDriver:无法连接到二进制文件

无法使用Selenium和Python连接到网页

Firefox 扩展的 Websocket 连接失败

使用python和selenium连接到phantomJs Webdriver时出现问题

RedHat 6.8 上的 Selenium Webdriver + geckodriver + python 2.6.6 + Firefox 无法打开浏览器

无法同时使用 Firefox 和 Chrome Webdriver 使用 Python Selenium 触发按钮

无法在python的硒Webdriver中加载Firefox

无法从 Python 连接到 RabbitMQ

Selenium Firefox 57无法连接到二进制/本地主机

在Firefox中使用Nightwatch运行测试无法连接到Selenium服务器

如何使用 Selenium 检查 Firefox 扩展的元素

使用 selenium 启用扩展来运行 firefox

无法在Firefox中启用或禁用扩展

Firefox扩展无法访问本地存储

Chrome扩展程序无法连接到websocket

无法连接到推送扩展服务

Python:无法通过脚本启动Selenium Webdriver(Firefox),但可以通过命令行运行

Firefox无法通过Selenium WebDriver启动URL

Linux服务器中的Python Selenium“无法连接到服务%s”%self.path

Selenium 2.46.0 org.openqa.selenium.firefox.NotConnectedException:45000 毫秒后无法连接到端口 7055 上的主机 127.0.0.1。

为什么Firefox无法连接到Facebook?

我无法连接到Firefox OS设备

Selenium Python无法在Firefox中访问站点

Selenium :: Python :: Chrome 扩展

org.openqa.selenium.firefox.NotConnectedException:使用GeckoDriver和Firefox执行代码时无法连接到主机127.0.0.1