2024:chrome 无法访问 python selenium

问题描述 投票:0回答:1

我想用我的设置打开一个 chrome 窗口并通过 selenium 连接到它。

我启动 chrome,然后尝试连接,但我得到

selenium.common.exceptions.WebDriverException: Message: unknown error: cannot connect to chrome at localhost:9014 from chrome not reachable

from selenium import webdriver
options = webdriver.ChromeOptions()      
os.system('2024\\startchrome_dev.bat')


options.add_experimental_option("debuggerAddress", "localhost:9014")
options.add_argument('--no-sandbox')
driver = webdriver.Chrome(options=options)

chrome 启动,但 Selenium 无法访问它。

startchrome_dev.bat
包含

"C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe"  --remote-debugging-port=9014  --user-data-dir="Profile 1"

有什么想法吗?

python google-chrome selenium-webdriver
1个回答
0
投票

我做了一些测试,但添加 bianary_location 是错误的。您所要做的就是将 os.system 更改为 os.startfile,如下所示。

from selenium import webdriver
options = webdriver.ChromeOptions()      
#os.system('2024\\startchrome_dev.bat')
os.startfile('2024\\startchrome_dev.bat')

options.add_experimental_option("debuggerAddress", "localhost:9014")
options.add_argument('--no-sandbox')
driver = webdriver.Chrome(options=options)
© www.soinside.com 2019 - 2024. All rights reserved.