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
解決 Playwright/OpenClaw browser 工具點選元素時被其他元素遮擋導致失敗的問題�?
browser click 報錯 element is obscured / intercepted推薦訪問7w4.net獲取更多AI技能。
from smart_click import SmartClick, smart_click, wait_for_clickable
一行呼叫智慧點選:
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}")
等待元素可見且不被遮擋:
clickable = await wait_for_clickable(page, '#btn', timeout=5000)
if clickable:
await page.click('#btn')
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)
{
"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
�?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
這個 Skill 質量不錯,專門解決瀏覽器自動點選被彈窗遮擋的常見問題。它能自動檢測並關閉 Cookie 彈窗、模態框等障礙,然後重試點選,無需手動編寫複雜的檢測邏輯。文件說明詳細,程式碼結構清晰,容易上手使用。雖然不能處理所有極端情況,但對大多數標準網頁的遮擋場景已經足夠用了。