v1.10.82-f67ee7d
Skip to main content
← Back to Hex Proxies

Selenium Proxy Setup

Configure proxies in Selenium WebDriver for Python and Java. Browser automation proxy setup with Hex Proxies residential IPs.

Requirements

  • Python 3.8+
  • Chrome/Firefox browser installed
  • ChromeDriver or GeckoDriver matching browser version
  • selenium-wire for authenticated proxies

Installation

pip install selenium selenium-wire

Code Example

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

# 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()

Setup Steps

1

Install Selenium and Selenium Wire

Run pip install selenium selenium-wire. Download the matching ChromeDriver for your Chrome version.

2

Configure Selenium Wire proxy

Create the seleniumwire_options dict with your Hex Proxies gateway URL and credentials.

3

Launch the browser

Use sw_webdriver.Chrome() with both seleniumwire_options and chrome_options for authenticated proxied browsing.

4

Navigate and verify

Load httpbin.org/ip and confirm the page shows a Hex Proxies IP address, not your real IP.

5

Set realistic fingerprints

Configure user agent, viewport, and disable navigator.webdriver to reduce bot detection alongside proxy usage.

6

Clean up resources

Always call driver.quit() in a finally block to close the browser and free the Selenium Wire proxy port.

Configuration Options

OptionDescription
Proxy Servergate.hexproxies.com:8080 via Selenium Wire proxy config or Chrome --proxy-server flag.
AuthenticationSelenium Wire handles auth automatically from credentials in the proxy URL.
Page Timeoutdriver.set_page_load_timeout(60) for proxied navigation. Increase for heavy pages.
No Proxy ListExclude localhost and internal addresses from proxy routing.
Headless Mode--headless=new flag reduces memory 30-40% while keeping full proxy support.

Best Practices

  • Use Selenium Wire instead of bare Selenium for authenticated proxy support with Hex Proxies.
  • Always call driver.quit() in a finally block to prevent orphaned Chrome processes.
  • Run headless mode in production to reduce memory usage by 30-40% per instance.
  • Set realistic user agent, viewport, and disable navigator.webdriver for anti-detection alongside proxy IPs.
  • Limit concurrent browser instances to 10-20 per server; each uses 150-250MB RAM with Selenium Wire.
  • Use page load strategy "eager" for faster navigation when you do not need all subresources.
  • Store proxy credentials in environment variables and read them when building seleniumwire_options.
  • Implement a browser pool with creation and destruction lifecycle to manage resources over long runs.

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-wire

Basic 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.

  1. selenium.common.exceptions.WebDriverException: ERR_PROXY_CONNECTION_FAILED
  2. - The browser cannot reach the proxy gateway
  3. - Verify gate.hexproxies.com:8080 is accessible from your machine
  4. - 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.

Error Handling

## Error Handling

Selenium proxy errors manifest as WebDriver exceptions during page navigation.

1. 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.

Frequently Asked Questions

Why can't standard Selenium handle proxy authentication?

Chrome DevTools Protocol does not support Proxy-Authorization headers. Use Selenium Wire, which intercepts traffic through a local mitmproxy to inject credentials.

Does Selenium Wire add latency?

Selenium Wire adds 5-15ms per request for local traffic interception. This is negligible compared to proxy and network latency.

How do I rotate IPs with Selenium?

Create a new driver instance for each IP rotation, or use Hex Proxies session parameters in the proxy URL for timed rotation without restarting the browser.

Can I run multiple Selenium instances with proxies?

Yes. Each Selenium Wire instance uses a separate local port. Limit to 10-20 concurrent instances per server to manage memory usage.

Ready to Get Started?

Set up Selenium with Hex Proxies in minutes.