当前位置: 首页 > news >正文

selenium SessionNotCreatedException问题解决办法

        在上周有一台服务器重启之后,Chrome浏览器也自动升了级,原本能够正常使用的自动化办公程序突然没法用了,出现了下面的报错提示。

codes/addCancelBdld.py:980: DeprecationWarning: use options instead of chrome_optionsdriver = webdriver.Chrome(executable_path='./chromedriver.exe', desired_capabilities=desired_capabilities, chrome_options=chrome_options)
[13908:16748:0731/133626.719:ERROR:net\base\network_change_notifier_win.cc:189] WSALookupServiceBegin failed with: 8DevTools remote debugging requires a non-default data directory. Specify this using --user-data-dir.
[6080:23036:0731/133626.876:ERROR:net\base\network_change_notifier_win.cc:189] WSALookupServiceBegin failed with: 8
WARNING: All log messages before absl::InitializeLog() is called are written to STDERR
I0000 00:00:1753940192.016375    5356 voice_transcription.cc:58] Registering VoiceTranscriptionCapability
[13908:16748:0731/133643.763:ERROR:components\device_event_log\device_event_log_impl.cc:198] [13:36:43.764] Bluetooth: bluetooth_adapter_winrt.cc:1054 Getting Default Adapter failed.
......
selenium.common.exceptions.SessionNotCreatedException: Message: session not created: DevToolsActivePort file doesn't exist

        经过多次询问DeepSeek也未能找到原因,但好在我已经找到了解决方法。

        我在代码中指定了--user-data-dir为User Data目录。这是导致代码运行时出现上面报错的罪魁祸首。

chrome_options.add_argument(f"--user-data-dir={os.path.join(os.environ['USERPROFILE'], fr'AppData/Local/Google/Chrome/User Data')}")

        我将User Data目录更名为Selenium Data,并将代码中的--user-data-dir指定为更名后的Selenium Data目录,代码就能正常使用了。

        最后,右键桌面上的Chrome快捷方式,点属性,在目标那一栏的内容后面加上--user-data-dir,也指定为更名后的Selenium Data目录。

--user-data-dir="%LOCALAPPDATA%\Google\Chrome\Selenium Data"

        这样桌面上的Chrome快捷方式也能正常使用了。

http://www.dtcms.com/a/320825.html

相关文章:

  • 讲一讲@ImportResource
  • NFS/SMB 共享目录
  • HTML应用指南:利用GET请求获取全国Apple Store 零售店位置信息
  • Dify + Ragflow的部署与服务体系
  • 【数据结构】哈希扩展学习
  • Zoho CRM API 配置和使用
  • Pytest项目_day10(接口的参数传递)
  • 创始人 IP 打造的 “内容 + 商业” 双体系
  • Redis数据组织方式
  • 20250808:EasyGBS 对接大华 ICC 平台问题处理
  • 使用Prometheus + Grafana + node_exporter实现Linux服务器性能监控
  • zookeeper3.8.4安装以及客户端C++api编译
  • WebForms 实例
  • 如何在Vue中使用拓扑图功能
  • 【深度学习计算性能】02:异步计算
  • 【入门级-C++程序设计:9、函数与递归-传值参数与传引用参数】
  • 数据持久化 —— `chrome.storage` 的记忆魔法
  • 服务器硬件电路设计之I2C问答(一):为什么I2C总线要加上拉电阻?
  • 华为USG防火墙双机,但ISP只给了1个IP, 怎么办?
  • WinForm 对话框的 Show 与 ShowDialog:阻塞与非阻塞的抉择
  • Java机密计算新维度:基于AMD SEV-ES的Enclave数据湖安全架构
  • 离线安装大语言模型管理工具Ollama
  • ArgoCD 与 GitOps:K8S 原生持续部署的实操指南
  • 使用 Grunt 替换 XML 文件中的属性值
  • Linux下GCC的C++实现Hive到Snowflake数据迁移
  • 在Java中,守护线程(Daemon Thread)和用户线程(User Thread)以及本地线程(Native Thread)的区别
  • 豆包新模型+PromptPilot:AI应用开发全流程实战指南
  • 深入掌握Prompt工程:高效构建与管理智能模型提示词全流程实战
  • Flutter Packge - 组件应用
  • [链表]142. 环形链表 II