修复百世优惠券广告弹窗从未关闭的问题

- 新增 site_baishi.dismiss_baishi_popups():优惠券广告为全屏居中 Ant Design
  modal,关闭键是 .ant-modal-close(纯图标、无文字)。旧逻辑只识别 '关 闭'/
  '阅读完毕' 等文字按钮,广告关闭键无文字故从未被关闭;现直接点击
  .ant-modal-close 并做重试 + 消失校验,再处理阅读消息与配置检查弹窗。
- runtime._dismiss_initial_popups 百世分支改为调用该 helper。
- 调试模式临时开启 CDP 9223 端口,便于 Playwright CLI 技能挂载已登录页面
  读取内容(仅调试模式生效,服务模式不受影响)。
This commit is contained in:
Misaka
2026-07-19 19:12:53 +08:00
parent 8f79cbc5d7
commit 076557aacb
2 changed files with 51 additions and 24 deletions

View File

@@ -48,6 +48,49 @@ def baishi_reset(page):
page.wait_for_timeout(1500)
def dismiss_baishi_popups(page):
"""清理百世首页杂乱弹窗:优惠券广告 / 阅读消息 / 配置检查弹窗。
优惠券广告是全屏居中 Ant Design modal.ant-modal-wrap.ant-modal-centered
其关闭键为右上角 .ant-modal-close纯图标、无文字。旧逻辑只识别 '关 闭' /
'阅读完毕' 等文字按钮,广告关闭键无文字,故广告从未被关闭。这里直接点
.ant-modal-close并做重试 + 消失校验。
"""
# 1) 优惠券广告弹窗(全屏居中 modal可能重复出现循环关到消失
for _ in range(4):
try:
ad = page.locator(".ant-modal-wrap.ant-modal-centered")
if ad.count() == 0 or not ad.first.is_visible(timeout=500):
break
close = ad.first.locator(".ant-modal-close")
if close.count() > 0:
close.first.click(timeout=3000)
page.wait_for_timeout(800)
except Exception:
pass
# 2) 阅读消息('阅读完毕' 按钮,可能多个)+ 3) 配置检查弹窗('关 闭' 按钮)
for _ in range(4):
handled = False
try:
read_btns = page.locator("button:has-text('阅读完毕')")
for i in range(read_btns.count()):
if read_btns.nth(i).is_visible(timeout=500):
read_btns.nth(i).click()
handled = True
except Exception:
pass
try:
if page.locator("button:has-text('关 闭')").is_visible(timeout=500):
page.locator("button:has-text('关 闭')").click()
handled = True
except Exception:
pass
if not handled:
break
page.wait_for_timeout(800)
def _remove_if_exists(path):
"""删除文件(若存在):流程开头清理上次的最终文件,避免无数据/失败时残留旧数据。"""
try: