簡體   English   中英

webdriver.Firefox() 與 selenium 的錯誤

[英]errors with webdriver.Firefox() with selenium

我正在使用 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'

我能做什么? 非常感謝任何幫助!

如果您使用的是 47.0.1 版本以上的 firefox,則您的系統路徑中需要有[geckodriver][1]可執行文件。 對於早期版本,您想關閉牽線木偶。 你可以這樣:

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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM