问题遇到的现象和发生背景
版本:selenium4.4.3
chrome : 75.0.3770.80
驱动版本跟浏览器版本一致
使用软件 PyCharm 2022.2.1 (Community Edition)Build #PC-222.3739.56
python 3.10.6
问题相关代码,请勿粘贴截图
from time import sleep
from selenium import webdriver
def open_chrome():
chrome=webdriver.Chrome()
chrome.get("http://www.baidu.com")
chrome.maximize_window()
print("url:",chrome.current_url)
print("title:",chrome.title)
sleep (3)
chrome.quit
open_chrome()
运行结果及报错内容
"C:\Program Files\Python310\python.exe" C:/code/python/py进阶/py04.py
Traceback (most recent call last):
File "C:\code\python\py进阶\py04.py", line 13, in <module>
open_chrome()
File "C:\code\python\py进阶\py04.py", line 5, in open_chrome
chrome=webdriver.Chrome()
File "C:\Program Files\Python310\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 69, in __init__
super().__init__(DesiredCapabilities.CHROME['browserName'], "goog",
File "C:\Program Files\Python310\lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 92, in __init__
super().__init__(
File "C:\Program Files\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 270, in __init__
self.start_session(capabilities, browser_profile)
File "C:\Program Files\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 363, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Program Files\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 428, in execute
self.error_handler.check_response(response)
File "C:\Program Files\Python310\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 243, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary
Stacktrace:
Backtrace:
Ordinal0 [0x01517DF3+1474035]
Ordinal0 [0x014907D1+919505]
Ordinal0 [0x0142CB43+510787]
Ordinal0 [0x013BDDE9+56809]
Ordinal0 [0x013E0CE4+199908]
Ordinal0 [0x013E069D+198301]
Ordinal0 [0x013DEECB+192203]
Ordinal0 [0x013C5FF6+90102]
Ordinal0 [0x013C765A+95834]
Ordinal0 [0x013C7554+95572]
GetHandleVerifier [0x0167231C+1249612]
GetHandleVerifier [0x015C1575+525221]
GetHandleVerifier [0x015C1310+524608]
Ordinal0 [0x01525D28+1531176]
GetHandleVerifier [0x015C1D4A+527226]
Ordinal0 [0x014A75F6+1013238]
Ordinal0 [0x014A746F+1012847]
Ordinal0 [0x014B365B+1062491]
Ordinal0 [0x014B379F+1062815]
Ordinal0 [0x014B2745+1058629]
BaseThreadInitThunk [0x77620419+25]
RtlGetAppContainerNamedObjectPath [0x77A872FD+237]
RtlGetAppContainerNamedObjectPath [0x77A872CD+189]
进程已结束,退出代码1
我的解答思路和尝试过的方法
根据查询到的解决方法 把驱动放到代码文件的路径下和在环境变量里配置chrome的路径 以及在定义函数括号里加上驱动路径 都是这样报错
我想要达到的结果
运行chrome浏览器