英文:
Use ChromeDriver while Chrome is running
问题
以下是您要翻译的内容:
在以下内容中,我正在使用Windows 10上的Selenium与Python(Git-Bash,而不是WSL)与ChromeDriver交互。
我目前使用的是Chrome版本114.0.5735.110,带有ChromeDriver 114.0.5735.90。以前,我相信我使用的是稍旧一点的Chrome版本(可能仍然是114.0.5735.xxx),带有我相信是ChromeDriver 114.0.5735.16。在旧的设置中,我以前能够在我的默认配置文件上保持Chrome处于打开状态,同时运行ChromeDriver(也在同一个默认配置文件上)。但自从升级后,我得到了一个很长的回溯,其中最相关的部分似乎是:
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed.
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location C:\Program Files\Google\Chrome\Application\chrome.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
只要在运行ChromeDriver之前关闭Chrome,完全相同的代码仍然可以工作。只有在Chrome打开时才会出现问题。似乎无论Chrome使用哪个配置文件都无所谓——我已经尝试过使用不同于ChromeDriver使用的配置文件以及相同的配置文件(都不起作用)。
我已经在Google上搜索了很多内容并参考了过去的Stack Overflow答案,但现有的解决方案似乎都不起作用。有什么想法可以提供吗?我真的希望在使用ChromeDriver的同时保持Chrome打开。
供参考,我的代码如下:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.binary_location = r"C:\Program Files\Google\Chrome\Application\chrome.exe"
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument(r'--user-data-dir=C:\Users\Issa\AppData\Local\Google\Chrome\User Data')
chrome_options.add_argument(r'--profile-directory=Profile 1')
chrome_options.add_argument('--headless=new')
# 禁用标志着“Chrome正在由自动化软件控制”的状态栏
chrome_options.add_experimental_option("useAutomationExtension", False)
chrome_options.add_experimental_option("excludeSwitches",["enable-automation"])
driver_service = Service(r'C:\Users\Issa\Downloads\chromedriver_win32\chromedriver.exe')
driver = webdriver.Chrome(service=driver_service, options=chrome_options)
driver.get("https://example.com")
driver.quit()
希望这有所帮助!
英文:
In the following, I am using Selenium with Python on Windows 10 (Git-Bash, not WSL) to interact with ChromeDriver.
I am currently on Chrome version 114.0.5735.110 with ChromeDriver 114.0.5735.90. Previously, I believe I was on a slightly older version of Chrome (probably still 114.0.5735.something) with I believe ChromeDriver 114.0.5735.16. On the older setup, I used to be able to keep Chrome open on my Default profile while simultaneously running ChromeDriver (also on that same Default profile). Since upgrading both, however, I get a long traceback whose most relevant part seems to be:
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed.
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location C:\Program Files\Google\Chrome\Application\chrome.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
The exact same code still works as long as Chrome is closed before running ChromeDriver. The issue only comes up when Chrome is open. It doesn't seem to matter what profile Chrome is using -- I've tried both using a different profile than the one ChromeDriver uses as well as the same profile (neither works).
I've googled around quite a bit and referenced past Stack Overflow answers, but none of the existing solutions seems to work. Any ideas on what I can do? I would really like to keep Chrome open while using ChromeDriver.
For reference, my code looks like this:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.binary_location = r"C:\Program Files\Google\Chrome\Application\chrome.exe"
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument(r"--user-data-dir=C:\Users\Issa\AppData\Local\Google\Chrome\User Data")
chrome_options.add_argument(r'--profile-directory=Profile 1')
chrome_options.add_argument('--headless=new')
# disable bar that says "chrome is being controlled by automated software"
chrome_options.add_experimental_option("useAutomationExtension", False)
chrome_options.add_experimental_option("excludeSwitches",["enable-automation"])
driver_service = Service(r'C:\Users\Issa\Downloads\chromedriver_win32\chromedriver.exe')
driver = webdriver.Chrome(service=driver_service, options=chrome_options)
driver.get("https://example.com")
driver.quit()
答案1
得分: 1
自上次更新以来,我遇到了相同的问题。
尝试重新安装Chrome,更新了Chrome驱动程序,将Chrome降级到上一个正常工作的版本。
对我来说都没有起作用。
我同意所有过去的解决方案也都不起作用。
切换到Edge直到问题解决。
英文:
Since last update i have the same issue.
Tried to re install chrome, updated the chromedriver, downgraded chrome to the last working.
Nothing worked for me.
I agree that all the past solutions are not working also.
switched to edge until is solved.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论