Browser Smart Click

👤 paudyyin 📦 v1.0.0 ⭐ 4.5 ⬇️ 190 下載
🤖 AI-Agent 免費

📖 技能介紹


name: browser-smart-click description: "Retry browser clicks with automatic obstacle detection and dismissal. Use when browser tool clicks fail due to cookie banners, modals, or fixed headers blocking the target element." tags: [browser, automation, playwright, click, overlay] dependencies: - playwright


browser-smart-click

解決 Playwright/OpenClaw browser 工具點選元素時被其他元素遮擋導致失敗的問題�?

何時使用

  • browser click 報錯 element is obscured / intercepted
  • 頁面�?cookie banner、modal overlay、fixed header 遮擋目標元素
  • 需要智慧等待元素變為可互動狀�?- 需要自動關閉彈窗後重試點選

    推薦訪問7w4.net獲取更多AI技能。

核心 API

Python 匯入

from smart_click import SmartClick, smart_click, wait_for_clickable

smart_click(page, selector, **options) �?ClickResult

一行呼叫智慧點選:

result = await smart_click(page, '#submit-btn')
if result.success:
    print("Clicked!")
else:
    print(f"Failed: {result.message}")
    if result.blocked:
        print(f"Blocked by: {result.blocker}")

wait_for_clickable(page, selector, timeout=10000) �?bool

等待元素可見且不被遮擋:

clickable = await wait_for_clickable(page, '#btn', timeout=5000)
if clickable:
    await page.click('#btn')

SmartClick 類(高階用法�?

sc = SmartClick(auto_dismiss=True, max_retries=3)

# 基礎點選
result = await sc.click(page, '#btn')

# 帶重試的點選(滾�?�?JS click 回退�?result = await sc.click_with_retry(page, '#btn', max_retries=3)

# 等待可點�?ok = await sc.wait_for_clickable(page, '#btn', timeout=10000)

ClickResult 格式

{
  "success": true,
  "target": {"selector": "#submit-btn", "text": "Submit"},
  "blocked": false,
  "blocker": null,
  "retry_count": 0,
  "message": "Clicked successfully"
}

被遮擋時�?

{
  "success": false,
  "target": {"selector": "#submit-btn", "text": "Submit"},
  "blocked": true,
  "blocker": {
    "tag": "div",
    "class_name": "cookie-banner",
    "text": "We use cookies",
    "bounding_box": {"x": 0, "y": 0, "width": 800, "height": 100},
    "attributes": {}
  },
  "retry_count": 1,
  "message": "Element blocked by: <div class=\"cookie-banner\"> text=\"We use cookies\""
}

自動處理策略

遮擋型別 檢測方�? 處理策略
Cookie Banner class/id 包含 cookie/consent/gdpr 點選 Accept/同意/允許 按鈕
Modal/Dialog role=dialog �?class 包含 modal/popup 點選 × 關閉按鈕,或�?Escape
Fixed Header style 包含 position:fixed/sticky 滾動頁面後重�?
未知遮擋 elementFromPoint 檢�? �?Escape 後重�?

檔案結構

skills/browser-smart-click/
├── SKILL.md                    # 本文�?├── scripts/
�?  ├── smart_click.py          # 核心實現
�?  └── test_smart_click.py     # 測試用例
└── references/
    └── usage.md                # 詳細使用文件

測試

cd skills/browser-smart-click/scripts
pytest test_smart_click.py -v

�?OpenClaw browser 工具配合

�?skill 不替�?OpenClaw browser 工具,而是作為補充�? 1. 先用 browser snapshot 獲取頁面狀�?2. �?browser act kind=click 嘗試點選 3. 如果失敗(遮擋),導�?smart_click 處理�? python from smart_click import smart_click result = await smart_click(page, '#target') 4. 或者在 OpenClaw �?browser act evaluate 中直接使用遮擋檢�?JS

🤖 AI 評測

這個 Skill 質量不錯,專門解決瀏覽器自動點選被彈窗遮擋的常見問題。它能自動檢測並關閉 Cookie 彈窗、模態框等障礙,然後重試點選,無需手動編寫複雜的檢測邏輯。文件說明詳細,程式碼結構清晰,容易上手使用。雖然不能處理所有極端情況,但對大多數標準網頁的遮擋場景已經足夠用了。

📊 多維度評分

適應性4.4
規範性4.2
有效性4.5
可靠性4.7
可信度4.5

📁 包含檔案 (6 個)

📄 SKILL.md 3.5 KB
📄 _meta.json 138 B
📄 references/usage.md 4.5 KB
📄 scripts/smart_click.py 26.4 KB
📄 scripts/test_smart_click.py 23.3 KB
📄 skill-card.md 2.1 KB