python - webdriver.Firefox() 与 selenium 的错误

标签 python selenium firefox

我正在使用 python 3.5、firefox 45(也尝试过 49)和 selenium 3.0.1

我尝试过:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()

然后我收到错误消息:

C:\Users\A\AppData\Local\Programs\Python\Python35\python.exe
C:/Users/A/Desktop/car/test.py
Traceback (most recent call last):
File "C:\Users\A\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\common\service.py", line 64, in start
stdout=self.log_file, stderr=self.log_file)
File "C:\Users\A\AppData\Local\Programs\Python\Python35\lib\subprocess.py", line 950, in __init__
restore_signals, start_new_session)
File "C:\Users\A\AppData\Local\Programs\Python\Python35\lib\subprocess.py", line 1220, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/A/Desktop/car/test.py", line 4, in <module>
driver = webdriver.Firefox()
File "C:\Users\A\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 135, in __init__
self.service.start()
File "C:\Users\A\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\common\service.py", line 71, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH. 
Exception ignored in: <bound method Service.__del__ of <selenium.webdriver.firefox.service.Service object at 0x0000000000EB8278>>
Traceback (most recent call last):
File "C:\Users\A\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\common\service.py", line 163, in __del__
self.stop()
File "C:\Users\A\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\common\service.py", line 135, in stop
if self.process is None:
AttributeError: 'Service' object has no attribute 'process'

我能做什么?非常感谢任何帮助!

最佳答案

如果您使用的是 Firefox 版本 >47.0.1,则您的系统路径中需要有 [geckodriver][1] 可执行文件。对于早期版本,您需要关闭 marionette。你可以这样:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
capabilities = DesiredCapabilities.FIREFOX.copy()
capabilities['marionette'] = False
driver = webdriver.Firefox(capabilities=capabilities)

关于python - webdriver.Firefox() 与 selenium 的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40142194/

相关文章:

php - 将 PHPUnit 与 Selenium 结合使用,如何测试元素是否包含某些内容?

python - “模板不存在”: template loader appears to be searching non-existent routes

java - 如何监听 Selenium 中的 CSS 变化?

python - round() 不会截断 float

java - Selenium 发送键(文本),从下拉列表中选择并按 Enter 键

javascript - 使用 Addon-SDK 在新选项卡/窗口中打开 XUL

jquery - FIrefox animate.css 动画不一致

javascript - 位置 :fixed difference in IE Vs Firefox

python - MySQL 连接器无法使用表别名

python - 如何创建自定义图层以在 Keras 中获取和操作渐变