[英]Cannot create instance of Selenium webdriver.Firefox()
I'm running Python 3.6.0 on Windows 7. I have installed Selenium version 3.3.1: 我在Windows 7上运行Python 3.6.0。我已经安装了Selenium版本3.3.1:
Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 07:18:10) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import selenium
>>> selenium.__version__
'3.3.1'
I also have the geckodriver executable in my Path: 我的Path中也有geckodriver可执行文件:
geckodriver.exe --version
geckodriver 0.15.0
I'm following the steps in the official Getting Started guide for Selenium 我正在按照Selenium官方入门指南中的步骤进行操作
>>> from selenium import webdriver
>>> from selenium.webdriver.common.keys import Keys
>>> driver = webdriver.Firefox()
However, calling webdriver.Firefox()
never returns an instance. 但是,调用webdriver.Firefox()
永远不会返回实例。 It simply hangs there until I manually hit ctrl+c
, at which point the following stack trace is printed out: 它只是挂在那里,直到我手动按下ctrl+c
为止,此时将打印出以下堆栈跟踪:
>>> driver = webdriver.Firefox()
Traceback (most recent call last):
File "C:\Python36-32\lib\socket.py", line 586, in readinto
return self._sock.recv_into(b)
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "c:\dev_env\test\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 155, in __init__
keep_alive=True)
File "c:\dev_env\test\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 92, in __init__
self.start_session(desired_capabilities, browser_profile)
File "c:\dev_env\test\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 179, in start_session
response = self.execute(Command.NEW_SESSION, capabilities)
File "c:\dev_env\test\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 236, in execute
response = self.command_executor.execute(driver_command, params)
File "c:\dev_env\test\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 415, in execute
return self._request(command_info[0], url, body=data)
File "c:\dev_env\test\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 447, in _request
resp = self._conn.getresponse()
File "C:\Python36-32\lib\http\client.py", line 1331, in getresponse
response.begin()
File "C:\Python36-32\lib\http\client.py", line 297, in begin
version, status, reason = self._read_status()
File "C:\Python36-32\lib\http\client.py", line 258, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "C:\Python36-32\lib\socket.py", line 586, in readinto
return self._sock.recv_into(b)
KeyboardInterrupt
>>>
Why am I unable to create the browser
object as indicated in the official guide? 为什么我无法按照官方指南中的说明创建browser
对象?
I assume you already have geckodriver downloaded. 我认为您已经下载了geckodriver。 Now all you have to do is : 现在您要做的就是:
System.setProperty("webdriver.gecko.driver", path to geckodriver.exe);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.