使用指定Profile启动Chrome时Selenium连接失败求助
无法通过Options连接指定Chrome Profile的问题解决
在使用Selenium启动Chrome时,添加指定用户数据目录和Profile目录的参数后无法正常启动,不添加这些参数时一切正常。
用于指定Profile的代码片段:
options.add_argument('--user-data-dir={}'.format(user_data_dir)) options.add_argument('--profile-dir={}'.format(profile_dir))
已尝试添加以下参数但未解决问题:
options.add_argument("disable-infobars") options.add_argument("--disable-extensions") options.add_argument("--disable-gpu") options.add_argument("--disable-dev-shm-usage") options.add_argument("--no-sandbox")
收到的错误信息:
selenium.common.exceptions.SessionNotCreatedException: Message: session not created: Chrome failed to start: exited normally. (session not created: 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.) Stacktrace: GetHandleVerifier [0x00B26EE3+174339] (No symbol) [0x00A50A51] (No symbol) [0x00766FF6] (No symbol) [0x0078A756] (No symbol) [0x00787A0F] (No symbol) [0x007BE259] (No symbol) [0x007BDBBA] (No symbol) [0x007B6DA6] (No symbol) [0x00791034] (No symbol) [0x00791F8D] GetHandleVerifier [0x00BC4B1C+820540] sqlite3_dbdata_init [0x00C853EE+653550] sqlite3_dbdata_init [0x00C84E09+652041] sqlite3_dbdata_init [0x00C797CC+605388] sqlite3_dbdata_init [0x00C85D9B+656027] (No symbol) [0x00A5FE6C] (No symbol) [0x00A583B8] (No symbol) [0x00A584DD] (No symbol) [0x00A45818] BaseThreadInitThunk [0x76457BA9+25] RtlInitializeExceptionChain [0x77AABD2B+107] RtlClearBits [0x77AABCAF+191]
解决方法
- 关闭所有正在运行的Chrome进程:打开任务管理器,结束所有
chrome.exe进程后重新运行脚本 - 校验路径正确性:确认
user_data_dir是Chrome用户数据的绝对路径,profile_dir是该目录下存在的Profile文件夹名(比如Profile 1) - 添加调试端口参数:在Options中加入
options.add_argument('--remote-debugging-port=9222'),避免DevTools端口异常 - 以管理员权限执行脚本:右键点击脚本文件,选择“以管理员身份运行”,解决权限不足导致的目录访问问题
- 匹配ChromeDriver与Chrome版本:确保ChromeDriver的版本和本地安装的Chrome版本完全一致,版本不兼容会引发启动失败
内容的提问来源于stack exchange,提问作者vladik
相关产品推荐
相关产品推荐

