修复“清空聊天”功能失败#225
Merged
CJackHwang merged 1 commit intoCJackHwang:mainfrom Aug 8, 2025
Hidden character warning
The head ref may contain hidden characters: "\u4fee\u590d\u201c\u6e05\u7a7a\u804a\u5929\u201d\u529f\u80fd\u5931\u8d25"
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题描述 (Problem)
在处理完一个请求后,自动化的“清空聊天”功能失败。具体表现为,当点击“清空聊天”按钮后弹出的确认对话框中,程序无法点击“继续”按钮,导致后续所有请求被阻塞。
根本原因 (Root Cause)
该问题由 Google AI Studio 前端界面的更新导致,原始的 CSS 选择器已经失效。我们最初的修复尝试也不够精确,导致了后续的错误。
原始选择器失效: 项目中最初用于定位“继续”按钮的选择器 button.mdc-button:has-text("Continue") 已经过时。
中间修复不精确: 我们在修复过程中,尝试使用 [ms-button].primary 作为新的选择器。但根据错误日志,这个选择器不够精确,它匹配到了页面上的多个元素(包括“Get API key”按钮),违反了 Playwright 的严格模式,该模式要求选择器必须指向唯一元素。
对话框容器变更: 旧的对话框遮罩层选择器 div.cdk-overlay-backdrop 也不再准确,新的对话框使用了不同的容器类。
解决方案 (Solution)
为了解决这个问题,我们对 config/selectors.py 文件进行了精确的更新:
更新确认按钮选择器:
文件: config/selectors.py:14
最终选择器: button.primary:has-text("Continue")
说明: 这个最终的选择器通过组合类名 .primary 和伪类 :has-text("Continue"),确保了只精确匹配文本内容为 "Continue" 的主操作按钮,从而解决了选择器不唯一的问题。
更新对话框容器选择器:
文件: config/selectors.py:24
旧选择器: div.cdk-overlay-backdrop
新选择器: .mat-mdc-dialog-inner-container
说明: 更新为新的对话框内部容器选择器,使程序能够更稳定地等待对话框出现。
通过以上修改,自动化脚本现在可以准确地定位并点击确认按钮,恢复了“清空聊天”功能的正常运作。