Chrome启动后崩溃[Selenium] [Python] [英] Chrome crashes after launching [Selenium] [Python]
问题描述
我写了一个小脚本来加载我的默认Chrome配置文件,并使用Selenium打开一个网站。但是,在chrome成功启动后,代码会暂停一段时间,然后崩溃。
我的脚本:
选项= webdriver.ChromeOptions()
options.add_argument( - user-data-dir = C:\\Users\\hbur3\\AppData\\Local\\Google \\Chrome\\\\ User Data)
options.add_argument( - start-maximized);
wd = webdriver.Chrome(chrome_options = options)
wd.get(https://google.com.au/)
Python错误:
selenium。 (驱动程序信息:chromedriver = 2.27.440174(e97a722caafc2d3a8b807ee115bfb307f7d2cfd9),platform = Windows NT 10.0.14393 x86_64)
Chromedriver日志:
[2.638] [INFO]:启动chrome:C:\程序文件(x86)\Google\Chrome\Application\chrome.exe--disable-background-networking - disable-client-side-phishing-detection --disable-default-apps --disable-hang-monitor --disable-infobars --disable-popup-blocking --disable-prompt-on-repost --disable-sync - -disable-web-resources --enable-logging --ignore-certificate-errors --load-component-extension =C:\Users\hbur3\AppData\Local\Temp \\ scoped_dir21208_8173\internal--log-level = 0 - 仅限记录 - 无首次运行--password-store = basic --remote-debugging-port = 12638 --safebrowsing-disable-auto -update --start-maximized --test-type = webdriver --use-mock-keychain --user-data-dir =C:\Users\hbur3\AppData\Local\Google\Chrome \用户数据
[2.641] [DEBUG]:DevTools请求:http:// localhost:12638 / json / version
[4.644] [DEBUG]:DevTools请求失败
[4.695 ] [DEBUG]:DevTools请求:http:// localhost:12638 / json / version
[4.896] [DEBUG]:DevTools请求失败
[4.946] [DEBUG]:DevTools请求:http:/ / localhost:12638 / json / version
[6.699] [DEBUG]:DevTools请求失败
[6.750] [DEBUG]:DevTools请求:http:// localhost:12638 / json / version
[6.950] [DEBUG]:DevTools请求失败
等...
我有尝试了一整套解决方案,包括:
- 缰绳创建新的Chrome用户个人资料
- 在其他地方复制默认个人资料
- 仅在没有其他Chrome窗口已打开
我厌恶删除我的个人资料并重新安装Chrome,但这可能是我唯一的解决方案。
我认为你需要做你害怕的事情...看到这个回答。您可以导出并导入您的个人资料以节省时间。
您可以尝试的另一件事是启动 RemoteWebDriver
而不是 ChromeDriver
。首先运行 chromedriver.exe
,然后连接到它:
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
driver = webdriver.Remote(
command_executor ='http:// localhost:9515 /',
desired_capabilities = DesiredCapabilities.CHROME)
如果您的问题仍然存在,请查找打开的问题或者打开一个新文件。
I have written a small script to load my default Chrome profile and open a site using Selenium. However, after chrome successfully launches, the code pauses for a while and then crashes.
My script:
options = webdriver.ChromeOptions()
options.add_argument("--user-data-dir=C:\\Users\\hbur3\\AppData\\Local\\Google\\Chrome\\User Data")
options.add_argument("--start-maximized");
wd = webdriver.Chrome(chrome_options=options)
wd.get("https://google.com.au/")
Python error:
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed
(Driver info: chromedriver=2.27.440174 (e97a722caafc2d3a8b807ee115bfb307f7d2cfd9),platform=Windows NT 10.0.14393 x86_64)
Chromedriver log:
[2.638][INFO]: Launching chrome: "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --disable-background-networking --disable-client-side-phishing-detection --disable-default-apps --disable-hang-monitor --disable-infobars --disable-popup-blocking --disable-prompt-on-repost --disable-sync --disable-web-resources --enable-logging --ignore-certificate-errors --load-component-extension="C:\Users\hbur3\AppData\Local\Temp\scoped_dir21208_8173\internal" --log-level=0 --metrics-recording-only --no-first-run --password-store=basic --remote-debugging-port=12638 --safebrowsing-disable-auto-update --start-maximized --test-type=webdriver --use-mock-keychain --user-data-dir="C:\Users\hbur3\AppData\Local\Google\Chrome\User Data"
[2.641][DEBUG]: DevTools request: http://localhost:12638/json/version
[4.644][DEBUG]: DevTools request failed
[4.695][DEBUG]: DevTools request: http://localhost:12638/json/version
[4.896][DEBUG]: DevTools request failed
[4.946][DEBUG]: DevTools request: http://localhost:12638/json/version
[6.699][DEBUG]: DevTools request failed
[6.750][DEBUG]: DevTools request: http://localhost:12638/json/version
[6.950][DEBUG]: DevTools request failed
etc...
I have tried a whole range of solutions, including:
- Reinstalling Chromedriver
- Creating a new Chrome user profile
- Copying the default profile elsewhere
- Only running when no other Chrome windows were open
I'm loathed to delete my profile and reinstall Chrome, but this may be my only solution.
I think you'll need to do what you're afraid of... see this answer. you can export and import your profile to save time.
Another thing you can try is to start a RemoteWebDriver
instead of ChromeDriver
. First run the chromedriver.exe
, then connect to it:
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
driver = webdriver.Remote(
command_executor='http://localhost:9515/',
desired_capabilities=DesiredCapabilities.CHROME)
If your problem still reporduces, look for an open issue or perhaps open a new one.
这篇关于Chrome启动后崩溃[Selenium] [Python]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!