使用Selenium连接到Chrome Web驱动程序的问题

fruv7luv  于 2023-10-14  发布在  Go
关注(0)|答案(2)|浏览(393)

我一直试图通过Selenium访问谷歌Chrome,但无法连接到Chrome驱动程序。最初,我收到一个错误,说明我的Chrome版本不支持,但我随后下载了最新的一个关闭https://chromedriver.chromium.org/downloads,但我仍然得到一个错误。
我尝试了多种方法:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.support import expected_conditions as EC
from webdriver_manager.chrome import ChromeDriverManager
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select

driver=webdriver.Chrome()

输出量:

SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 114
Current browser version is 117.0.5938.150 with binary path C:\Program Files\Google\Chrome\Application\chrome.exe

然后我试了这个:

driver=webdriver.Chrome(service=Service(ChromeDriverManager().install()))

输出:ConnectionError: Could not reach host. Are you offline?
下一页:driver=webdriver.Chrome(ChromeDriverManager().install())
输出:ConnectionError: Could not reach host. Are you offline?
最后:driver=webdriver.Chrome(ChromeDriverManager())
输出量:

NoSuchDriverException: Message: Unable to obtain chromedriver using Selenium Manager; 'ChromeDriverManager' object has no attribute 'capabilities'; For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location

如果任何人对现在可能出现的问题有任何想法,我们将不胜感激。

1dkrff03

1dkrff031#

我不是PythonMaven,但我试过了,它工作了:

# Configure Chrome options.
opts = Options()

# Configure ChromeDriver service.
service = Service(ChromeDriverManager().install())

# Start the Chrome driver with the configured options and service.
driver = webdriver.Chrome(service=service, options=opts)
u0njafvf

u0njafvf2#

大家好,所以我想通了,我需要更新 selenium ,而不仅仅是我的chromedriver。我是通过以下方式做到这一点的:

pip install -U selenium

然后我用这个代码连接:

service = Service()
options = webdriver.ChromeOptions()
driver = webdriver.Chrome(service=service, options=options)

Shoutout这个视频:https://www.youtube.com/watch?v=BnY4PZyL9cg

相关问题