Selenium WebDriver的更新速度比Chrome快
我已经遇到这个问题两次:Selenium WebDriver更新后需要Chrome的新版本,但Chrome还检测不出新版本。第一次遇到时,Chrome需要大约15天才能赶上。
有没有办法强制更新Chrome,或者让Python使用旧版本的Selenium WebDriver?我在Windows 11上。
我尝试使用下面这段代码降级Selenium WebDriver,但仍然遇到同样的错误。
service = Service(ChromeDriverManager(driver_version="144").install())
browser = webdriver.Chrome(service=service)
Error:
Message: session not created: cannot connect to chrome at 127.0.0.1:56620
from session not created: This version of ChromeDriver only supports Chrome version 146
Current browser version is 145.0.7632.117; For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#sessionnotcreatedexception
Stacktrace:
undetected_chromedriver!GetHandleVerifier [0xd1e813+10ad3]
undetected_chromedriver!GetHandleVerifier [0xd1e944+10c04]
undetected_chromedriver!(No symbol) [0xb31fc0]
undetected_chromedriver!(No symbol) [0xb6d502]
undetected_chromedriver!(No symbol) [0xb6c52c]
undetected_chromedriver!(No symbol) [0xb62625]
undetected_chromedriver!(No symbol) [0xb62446]
undetected_chromedriver!(No symbol) [0xba96cf]
undetected_chromedriver!(No symbol) [0xba8ee7]
undetected_chromedriver!(No symbol) [0xb9d766]
undetected_chromedriver!(No symbol) [0xb700e9]
undetected_chromedriver!(No symbol) [0xb70ea4]
undetected_chromedriver!GetHandleVerifier [0xfa1359+293619]
undetected_chromedriver!GetHandleVerifier [0xf9ca7d+28ed3d]
undetected_chromedriver!GetHandleVerifier [0xfbab9b+2ace5b]
undetected_chromedriver!GetHandleVerifier [0xd389a8+2ac68]
undetected_chromedriver!GetHandleVerifier [0xd4049d+3275d]
undetected_chromedriver!GetHandleVerifier [0xd27328+195e8]
undetected_chromedriver!GetHandleVerifier [0xd274f2+197b2]
undetected_chromedriver!GetHandleVerifier [0xd1065a+291a]
KERNEL32!BaseThreadInitThunk [0x76275d49+19]
ntdll!RtlInitializeExceptionChain [0x7777d83b+6b]
ntdll!RtlGetAppContainerNamedObjectPath [0x7777d7c1+231]
解决方案
自Selenium 4.6起,新增了 Selenium Manager,它会自动为你下载并配置合适的驱动。因此,你不再需要使用DriverManager或指定路径等。
有了内部驱动管理器,它会下载与已安装浏览器匹配的驱动,因此应该能避免你描述的问题。
这就是你需要的全部代码...
from selenium import webdriver
driver = webdriver.Chrome()
driver.maximize_window()
driver.get('http://www.google.com')
站内所有文章版权归属LeftHeroAI导航站,无授权禁止任何主体转载、抄袭、复制内容,亦不得私自架设镜像站点。一经侵权,本站将通过法律途径追责。