iT邦幫忙

0

Python Selenium 4.10.0版本 webdriver.Chrome() 跑不出來

  • 分享至 

  • xImage

程式碼:
from selenium import webdriver
driver = webdriver.Chrome()

Output:
DevTools listening on ws://127.0.0.1:2649/devtools/browser/353db3c8-848f-47a8-9104-9829a63e280c
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\hp\anaconda3\envs\tensorflow\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 49, in init
super().init(
File "C:\Users\hp\anaconda3\envs\tensorflow\lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 54, in init
super().init(
File "C:\Users\hp\anaconda3\envs\tensorflow\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 206, in init
self.start_session(capabilities)
File "C:\Users\hp\anaconda3\envs\tensorflow\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 291, in start_session
response = self.execute(Command.NEW_SESSION, caps)["value"]
File "C:\Users\hp\anaconda3\envs\tensorflow\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 346, in execute
self.error_handler.check_response(response)
File "C:\Users\hp\anaconda3\envs\tensorflow\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 245, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 114
Current browser version is 116.0.5845.180 with binary path C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
Stacktrace:
Backtrace:
GetHandleVerifier [0x00726E73+48323]
(No symbol) [0x006B9661]
(No symbol) [0x005C5308]
(No symbol) [0x005E634C]
(No symbol) [0x005E2093]
(No symbol) [0x005E0719]
(No symbol) [0x00610DF5]
(No symbol) [0x00610ADC]
(No symbol) [0x0060A6D6]
(No symbol) [0x005E847C]
(No symbol) [0x005E957D]
GetHandleVerifier [0x0098FD5D+2575277]
GetHandleVerifier [0x009CF86E+2836158]
GetHandleVerifier [0x009C96DC+2811180]
GetHandleVerifier [0x007B41B0+626688]
(No symbol) [0x006C314C]
(No symbol) [0x006BF4B8]
(No symbol) [0x006BF59B]
(No symbol) [0x006B21B7]
BaseThreadInitThunk [0x778300C9+25]
RtlGetAppContainerNamedObjectPath [0x77E27B1E+286]
RtlGetAppContainerNamedObjectPath [0x77E27AEE+238]

我現在無法input這串進去,但我之前用一樣的程式碼卻跑得動QQ
有甚麼方法可以解嗎,還請各位大神幫幫忙了

ccutmis iT邦高手 2 級 ‧ 2023-09-07 19:39:49 檢舉
This version of ChromeDriver only supports Chrome version 114
Current browser version is 116.0.5845.180 with binary path
------
ChromeDriver版本跟 Chrome 版本不匹配
可能是 Chrome 更新了
你需要下載匹配的 ChromeDriver覆蓋舊的版本
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

1
Zero皇
iT邦研究生 2 級 ‧ 2023-09-07 21:05:13
最佳解答

如上面大大說的,瀏覽器的更新很頻繁,常常會有ChromeDriver版本跟瀏覽器不符的狀況,所以通常不是降低本機瀏覽器版本,就是更新webdrivers。

我在用OWASP ZAP的時候有遇到這題,你可以上網找更新的webdrivers,從ChromeDriver - WebDriver for Chrome - Version Selection看來,好像從115版以後最新的driver有集中管理:

For versions 115 and newer
Starting with M115 the ChromeDriver release process is integrated with that of Chrome. The latest Chrome + ChromeDriver releases per release channel (Stable, Beta, Dev, Canary) are available at the Chrome for Testing (CfT) availability dashboard. As a result, you might no longer have a need for version selection — you could choose any available CfT version and simply download the correspondingly-versioned ChromeDriver binary.

於是點進他的連結你會找到下載driver的地方,從log看來你本機Chrome版本是116.0.5845.180,所以你可以載相近的版本例如下面的Stable或Beta版試試。
https://ithelp.ithome.com.tw/upload/images/20230907/201409258CeaPvMtES.png

總之,下載新一點的webdrivers,讓Selenium用(Python Selenium指定ChromeDriver的部分可以參考這篇),應該可以試試看。

感謝大大解答,我換了新的driver但還是fail QQ,現在只能用colab做哈哈
driver.get(url)
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\hp\anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 355, in get
self.execute(Command.GET, {"url": url})
File "C:\Users\hp\anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 346, in execute
self.error_handler.check_response(response)
File "C:\Users\hp\anaconda3\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 245, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchWindowException: Message: no such window: target window already closed
from unknown error: web view not found
(Session info: chrome=116.0.5845.180)
Stacktrace:
GetHandleVerifier [0x00007FF79DF452A2+57122]
(No symbol) [0x00007FF79DEBEA92]
(No symbol) [0x00007FF79DD8E3AB]
(No symbol) [0x00007FF79DD6E1B9]
(No symbol) [0x00007FF79DDEB417]
(No symbol) [0x00007FF79DDFE24F]
(No symbol) [0x00007FF79DDE6DB3]
(No symbol) [0x00007FF79DDBD2B1]
(No symbol) [0x00007FF79DDBE494]
GetHandleVerifier [0x00007FF79E1EEF82+2849794]
GetHandleVerifier [0x00007FF79E241D24+3189156]
GetHandleVerifier [0x00007FF79E23ACAF+3160367]
GetHandleVerifier [0x00007FF79DFD6D06+653702]
(No symbol) [0x00007FF79DECA208]
(No symbol) [0x00007FF79DEC62C4]
(No symbol) [0x00007FF79DEC63F6]
(No symbol) [0x00007FF79DEB67A3]
BaseThreadInitThunk [0x00007FF885E07614+20]
RtlUserThreadStart [0x00007FF885FA26B1+33]

Zero皇 iT邦研究生 2 級 ‧ 2023-09-09 09:10:11 檢舉

selenium.common.exceptions.NoSuchWindowException: Message: no such window: target window already closed
driver視窗可能沒有成功打開,或是被關閉,或是沒有被切換到,這個我就不太會了
不過如果用colab能做,有可能差在套件版本

我要發表回答

立即登入回答