Selenium Browser Automation Skill
This skill provides comprehensive browser automation capabilities using Selenium WebDriver.
Quick Start
Basic form filling example:
CODEBLOCK0
Web scraping example:
CODEBLOCK1
Installation Requirements
Before using this skill, install the required dependencies:
CODEBLOCK2
Supported Browsers
- - Chrome: Full support with ChromeDriver
- Firefox: Full support with GeckoDriver
- Edge: Full support with EdgeDriver
- Safari: Limited support (macOS only)
Core Scripts
Form Filling (scripts/form_filler.py)
Automatically fill forms and submit data:
CODEBLOCK3
Web Scraper (scripts/web_scraper.py)
Extract data from web pages:
CODEBLOCK4
UI Tester (scripts/ui_tester.py)
Perform UI testing and validation:
CODEBLOCK5
Usage Examples
See examples/ for comprehensive examples including:
- - Form filling with various input types
- Web scraping with pagination
- UI testing workflows
- Error handling and retries
- Browser configuration options
Browser Configuration
The scripts support various browser configurations:
- - Headless mode for background automation
- Different viewport sizes
- Custom user agents
- Proxy support
- Download directory configuration
Error Handling
Comprehensive error handling for:
- - Element not found
- Page load timeouts
- Network issues
- Browser crashes
- Form validation errors
Advanced Features
- - Wait strategies: Explicit waits, implicit waits, fluent waits
- Element locators: ID, CSS selectors, XPath, name, class
- JavaScript execution: Run custom JavaScript in browser
- File uploads: Handle file input fields
- Cookies management: Get, set, and manage cookies
- Screenshots: Capture full page or element screenshots
Integration with Other Skills
This skill can be combined with:
- - browser-opener: Open browsers programmatically
- data-processing: Process scraped data
- file-operations: Save and manage output files
Selenium 浏览器自动化技能
本技能提供基于Selenium WebDriver的全面浏览器自动化能力。
快速开始
基础表单填写示例:
python
填写并提交表单
python scripts/form_filler.py --url https://example.com/login --username testuser --password testpass
网页抓取示例:
python
从网页提取数据
python scripts/web_scraper.py --url https://example.com/data --output results.csv
安装要求
使用本技能前,请安装所需依赖:
bash
pip install selenium webdriver-manager beautifulsoup4 pandas
支持的浏览器
- - Chrome:通过ChromeDriver提供完整支持
- Firefox:通过GeckoDriver提供完整支持
- Edge:通过EdgeDriver提供完整支持
- Safari:有限支持(仅限macOS)
核心脚本
表单填写(scripts/form_filler.py)
自动填写表单并提交数据:
python
python scripts/form_filler.py --url https://example.com/login --username testuser --password testpass
python scripts/form_filler.py --url https://example.com/contact --name 张三 --email john@example.com --message 你好
网页抓取器(scripts/web_scraper.py)
从网页提取数据:
python
python scripts/web_scraper.py --url https://example.com/products --output products.csv
python scripts/web_scraper.py --url https://example.com/news --output news.json --format json
UI测试器(scripts/ui_tester.py)
执行UI测试与验证:
python
python scripts/ui_tester.py --url https://example.com --element login-button --action click
python scripts/ui_tester.py --url https://example.com --element username --action type --text testuser
使用示例
详见examples/目录中的综合示例,包括:
- - 多种输入类型的表单填写
- 带分页功能的网页抓取
- UI测试工作流程
- 错误处理与重试机制
- 浏览器配置选项
浏览器配置
脚本支持多种浏览器配置:
- - 无头模式用于后台自动化
- 不同视口尺寸
- 自定义用户代理
- 代理支持
- 下载目录配置
错误处理
全面的错误处理机制:
- - 元素未找到
- 页面加载超时
- 网络问题
- 浏览器崩溃
- 表单验证错误
高级功能
- - 等待策略:显式等待、隐式等待、流畅等待
- 元素定位器:ID、CSS选择器、XPath、名称、类名
- JavaScript执行:在浏览器中运行自定义JavaScript
- 文件上传:处理文件输入字段
- Cookie管理:获取、设置和管理Cookie
- 截图功能:捕获全页面或元素截图
与其他技能的集成
本技能可与以下技能结合使用:
- - browser-opener:以编程方式打开浏览器
- data-processing:处理抓取的数据
- file-operations:保存和管理输出文件