已安裝完selenium
但是在pychream中執行卻出現以下錯誤
因為不知道是不是環境變數沒設好造成的
所以將環境變量一起截圖上來
請前輩們幫幫忙..!
path
pychram
pychram Commu
import os
import time
from selenium import webdriver
driver = webdriver.Chrome("C:\chromedriver-win64\chromedriver.exe")
driver.get("https://tw.yahoo.com/")
time.sleep(5)
driver.close()
錯誤訊息
C:\ProgramData\Anaconda3\python.exe C:\Users\FANMO4F\PycharmProjects\pythonProject2\005.py
Traceback (most recent call last):
File "C:\Users\FANMO4F\AppData\Roaming\Python\Python39\site-packages\selenium\webdriver\common\driver_finder.py", line 38, in get_path
path = SeleniumManager().driver_location(options) if path is None else path
File "C:\Users\FANMO4F\AppData\Roaming\Python\Python39\site-packages\selenium\webdriver\common\selenium_manager.py", line 71, in driver_location
browser = options.capabilities["browserName"]
AttributeError: 'str' object has no attribute 'capabilities'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\FANMO4F\PycharmProjects\pythonProject2\005.py", line 4, in <module>
driver = webdriver.Chrome("C:\chromedriver-win64\chromedriver.exe")
File "C:\Users\FANMO4F\AppData\Roaming\Python\Python39\site-packages\selenium\webdriver\chrome\webdriver.py", line 45, in __init__
super().__init__(
File "C:\Users\FANMO4F\AppData\Roaming\Python\Python39\site-packages\selenium\webdriver\chromium\webdriver.py", line 51, in __init__
self.service.path = DriverFinder.get_path(self.service, options)
File "C:\Users\FANMO4F\AppData\Roaming\Python\Python39\site-packages\selenium\webdriver\common\driver_finder.py", line 40, in get_path
msg = f"Unable to obtain driver for {options.capabilities['browserName']} using Selenium Manager."
AttributeError: 'str' object has no attribute 'capabilities'
我記得 selenium 最新版好像不需要下載 driver,直接調用 Chrome() 就會自己幫你處理了,可以試試看,或是可以使用 webdriver-manager 這個套件