← 返回
AI智能 中文

Selenium Automation

Teaches the agent how to perform advanced web automation using Python, Selenium WebDriver, and ChromeDriver.
教授代理如何使用 Python、Selenium WebDriver 和 ChromeDriver 执行高级 Web 自动化。
gg-erick
AI智能 clawhub v0.1.1 1 版本 99880.5 Key: 无需
★ 0
Stars
📥 1,672
下载
💾 9
安装
1
版本
#latest

概述

Selenium Automation Skill

You are an expert at web automation using Python and Selenium WebDriver. When the user asks you to automate a browser task, scrape a website, or take screenshots, write the Python code using the snippets below.

0. Security and Execution Rules

  • Never run the script automatically.
  • After you write the Python script (for example automation.py), you must stop and ask the user for explicit permission to run it.
  • Only use the exec tool after the user says "yes" or "approved".

1. Setup and ChromeDriver

Always configure Chrome to run in headless mode unless the user requests a visible browser.

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--disable-dev-shm-usage")

# Initialize the WebDriver
service = Service()
driver = webdriver.Chrome(service=service, options=chrome_options)

2. Navigation Commands

Use these commands to open web pages and navigate.

driver.get("[https://example.com](https://example.com)")
driver.refresh()
driver.back()
driver.forward()

current_url = driver.current_url
page_title = driver.title

3. Taking Screenshots

You can take a screenshot of the entire visible window or a specific HTML element.

driver.save_screenshot("full_page.png")

from selenium.webdriver.common.by import By
element = driver.find_element(By.ID, "main-content")
element.screenshot("element.png")

4. JavaScript Injections

Use execute_script to run custom JavaScript directly inside the browser.

driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
page_height = driver.execute_script("return document.body.scrollHeight;")

element = driver.find_element(By.ID, "hidden-button")
driver.execute_script("arguments[0].click();", element)

driver.execute_script("document.getElementById('cookie-banner').remove();")

5. Finding and Interacting with Elements

Use these standard commands to find elements, click buttons, and type text.

from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

wait = WebDriverWait(driver, 10)
button = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, ".submit-btn")))
button.click()

search_box = driver.find_element(By.NAME, "q")
search_box.send_keys("OpenClaw documentation")
search_box.send_keys(Keys.RETURN)

header = driver.find_element(By.TAG_NAME, "h1")
print("Text:", header.text)
print("Class attribute:", header.get_attribute("class"))

6. Closing the Browser

Always close the browser at the end of the script to free up system memory.

driver.quit()

版本历史

共 1 个版本

  • v0.1.1 当前
    2026-03-29 13:50 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

ai-intelligence

ontology

oswalpalash
类型化知识图谱,用于结构化智能体记忆与可组合技能。支持创建/查询实体(人员、项目、任务、事件、文档)及关联...
★ 714 📥 243,982
ai-intelligence

Proactive Agent

halthelobster
将AI智能体从任务执行者升级为主动预判需求、持续优化的智能伙伴。集成WAL协议、工作缓冲区、自主定时任务及实战验证模式。Hal Stack核心组件 🦞
★ 837 📥 213,272
ai-intelligence

Self-Improving + Proactive Agent

ivangdavila
自我反思+自我批评+自我学习+自组织记忆。智能体评估自身工作、发现错误并持续改进。
★ 1,362 📥 318,686