Selenium Integration
Selenium is the most widely-used browser automation framework supporting multiple browsers and languages. Connect it to Scrapfly Cloud Browser using the Chrome DevTools Protocol (CDP) for scalable automation with built-in proxies and fingerprinting.
Installation & Quick Start
Install Selenium and connect to Cloud Browser:
WebSocket Connection Parameters
The Cloud Browser WebSocket URL accepts the following query parameters:
| Parameter | Required | Description | Example |
|---|---|---|---|
api_key |
Required | Your Scrapfly API key | YOUR_API_KEY |
proxy_pool |
Optional | Proxy type: datacenter or residential |
datacenter |
os |
Optional | Operating system fingerprint: linux, windows, or macos |
linux |
session |
Optional | Session ID for persistent browser state (cookies, storage) | my-session-123 |
country |
Optional | Proxy country code (ISO 3166-1 alpha-2) | us, uk, de |
Data Extraction
Extract data from a dynamic page using Selenium's powerful element selection:
Form Interaction
Fill forms and handle login flows using Selenium's robust element interaction:
Session Persistence
Maintain browser state across connections using the session parameter:
Proxy Options
| Proxy Pool | Use Case | Cost |
|---|---|---|
datacenter |
General scraping, high speed, lower cost | 1 credits/30s + 2 credits/MB |
residential |
Protected sites, geo-targeting, anti-bot bypass | 1 credits/30s + 10 credits/MB |
Best Practices
- Use explicit waits - Leverage
WebDriverWaitandexpected_conditionsfor reliable element interactions - Handle disconnects - Wrap connections in try/except (Python) or try/catch (JavaScript)
- Close browsers - Always call
driver.quit()to stop billing and release resources - Use sessions wisely - Reuse sessions for multi-step flows to maintain login state
- Leverage Selenium features - Use element locators (By.ID, By.CLASS_NAME, etc.) and built-in waits
- Upgrade to Selenium 4.10+ - For better CDP and WebDriver BiDi support
Troubleshooting
Cause: CDP connection via debuggerAddress may not be supported in older Selenium versions.
Solution: Upgrade to Selenium 4.10+ or use WebDriver BiDi connection method.
Cause: WebSocket connection to Cloud Browser failed or timed out.
Solution: Verify your API key and check network connectivity. Ensure your firewall allows WebSocket connections.
Cause: Session ID not provided or session expired.
Solution: Always include the same session parameter in the WebSocket URL for persistent sessions.
Note: Sessions expire after 1 hour of inactivity by default.