Selenium Proxy Setup
Selenium WebDriver has a fundamental limitation with authenticated proxies: the Chrome DevTools Protocol does not support Proxy-Authorization headers natively. Unauthenticated proxies work via the --proxy-server Chrome flag, but adding credentials requires either Selenium Wire (a drop-in replacement that intercepts traffic) or a Chrome extension that injects authentication headers.
Selenium Wire wraps the standard Selenium WebDriver and adds a mitmproxy-based interception layer that handles proxy auth transparently. The trade-off is slightly higher memory usage (50-100MB per browser instance) and an additional local port per session.
Prerequisites
Before you begin, make sure you have: - An active Hex Proxies account with proxy credentials - Python 3.8+ - Chrome or Firefox browser installed - ChromeDriver or GeckoDriver matching your browser version - selenium-wire package for authenticated proxy support
Installation
pip install selenium selenium-wireBasic Proxy Configuration
For unauthenticated proxies, pass --proxy-server as a Chrome argument. For authenticated proxies with Hex Proxies, use Selenium Wire's proxy configuration dictionary.
from selenium import webdriver# Chrome proxy setup (unauthenticated) chrome_options = Options() chrome_options.add_argument( '--proxy-server=http://gate.hexproxies.com:8080' )
# For authenticated proxies, use Selenium Wire from seleniumwire import webdriver as sw_webdriver
sw_options = { 'proxy': { 'http': 'http://user:pass@gate.hexproxies.com:8080', 'https': 'http://user:pass@gate.hexproxies.com:8080', 'no_proxy': 'localhost,127.0.0.1', } }
driver = sw_webdriver.Chrome( seleniumwire_options=sw_options, options=chrome_options, )
try: driver.get('https://httpbin.org/ip') print(driver.page_source) finally: driver.quit() ```
Headless Mode with Proxies
Add chrome_options.add_argument('--headless=new') for headless operation. Headless Chrome uses the same proxy configuration as headed mode but uses less memory, making it practical to run 10-20 concurrent browser instances with proxies on a single server.
Fingerprint Considerations
Selenium's default WebDriver fingerprint is detectable by anti-bot systems. When using Hex Proxies residential IPs with Selenium, also configure: a realistic user agent, a standard viewport size (1920x1080), and disable the navigator.webdriver flag to reduce detection. Hex Proxies handles the IP reputation; you handle the browser fingerprint.
Configuration Options
- **Proxy Server** -- gate.hexproxies.com:8080 via --proxy-server flag or Selenium Wire config dict.
- **Authentication** -- Selenium Wire handles Proxy-Authorization automatically from the URL credentials.
- **Page Load Timeout** -- driver.set_page_load_timeout(60) for proxied page loads that take longer.
- **No Proxy List** -- Exclude localhost and internal domains from proxy routing with no_proxy.
- **User Agent** -- Set via chrome_options.add_argument('--user-agent=...') for realistic fingerprinting.
Error Handling
Selenium proxy errors manifest as WebDriver exceptions during page navigation.
- selenium.common.exceptions.WebDriverException: ERR_PROXY_CONNECTION_FAILED
- - The browser cannot reach the proxy gateway
- - Verify gate.hexproxies.com:8080 is accessible from your machine
- - Check that Selenium Wire's internal port (default 8087) is not blocked
2. Page Load Timeout After 60 Seconds - The proxied page load exceeded the timeout threshold - Increase timeout: driver.set_page_load_timeout(120) - Use 'eager' page load strategy to proceed before all resources load
3. Selenium Wire Certificate Warning - Selenium Wire uses a local CA for HTTPS interception - Add chrome_options.add_argument('--ignore-certificate-errors') for Selenium Wire only - This is safe because Selenium Wire's CA is local to your machine
4. Browser Crash Under Load (Memory) - Each Selenium Wire instance uses 150-250MB of RAM - Limit concurrent instances and call driver.quit() promptly - Use headless mode to reduce per-instance memory by 30-40%
5. Anti-Bot Detection (403 / CAPTCHA) - Set a realistic user agent and viewport size - Disable navigator.webdriver with execute_cdp_cmd - Use Hex Proxies residential IPs for highest trust scores ```
Always use try/finally with driver.quit() to clean up browser processes and avoid zombie Chrome instances.