.bp-clean-small-figure{max-width:540px!important;width:100%!important;margin:22px auto!important;padding:10px!important;border-radius:20px!important;background:#fff!important;box-shadow:0 10px 28px rgba(7,18,5,.10)!important}.bp-clean-small-figure img,.bp-clean-small-image{display:block!important;width:100%!important;height:auto!important;border-radius:16px!important}.bp-clean-small-figure figcaption{font-size:14px!important;line-height:1.45!important;color:#4b5563!important;margin-top:10px!important;text-align:center!important}

WebDriver automation guide

How to Use Proxies with Selenium

Configure HTTP, HTTPS and SOCKS proxies in Selenium WebDriver with Python examples, practical authentication choices, stable sessions and layered troubleshooting.

Selenium WebDriver proxy configuration
A supportable Selenium proxy setup creates explicit capabilities, verifies the exit and cleans up every driver session.

Short answer: how to use a proxy with Selenium

Selenium WebDriver can configure manual HTTP, SSL and SOCKS proxies through the standard proxy capability attached to browser options. In Python, create a Proxy, set its type and endpoints, assign it to ChromeOptions or FirefoxOptions, then start the driver. Verify the public exit before the application test and always quit the driver in cleanup.

The official Selenium Python API documents the Proxy class and ProxyType values. Username/password authentication for HTTP proxies is not a portable standard WebDriver capability, so choose IP allowlisting or another explicitly supported credential path instead of assuming credentials embedded in a URL will work in every browser.

Testing boundary: automate browsers, accounts and destinations you are authorized to test. Keep request volume responsible and do not use proxy rotation to bypass limits or platform safeguards.

Selenium proxy configuration in Python

This example uses the standard Selenium proxy object and an IP-allowlisted endpoint. The same manual proxy is assigned to HTTP and HTTPS traffic.

import json
import os
from selenium import webdriver
from selenium.webdriver.common.proxy import Proxy, ProxyType

proxy_host = os.environ["PROXY_HOST"]
proxy_port = os.environ["PROXY_PORT"]
endpoint = f"{proxy_host}:{proxy_port}"

proxy = Proxy()
proxy.proxy_type = ProxyType.MANUAL
proxy.http_proxy = endpoint
proxy.ssl_proxy = endpoint
proxy.no_proxy = "localhost,127.0.0.1"

options = webdriver.ChromeOptions()
options.proxy = proxy

driver = webdriver.Chrome(options=options)
try:
    driver.get("https://api.ipify.org?format=json")
    result = json.loads(driver.find_element("tag name", "body").text)
    print("Proxy exit:", result["ip"])
finally:
    driver.quit()

The official driver session documentation includes proxy options in the browser configuration examples. Keep Selenium and the browser driver current enough to support the selected browser, and test a direct baseline before adding the proxy.

If you use an authenticated endpoint, do not hardcode credentials into endpoint. Standard HTTP proxy authentication support differs between browsers and drivers. Prefer an assigned IP allowlist when available, or a controlled local gateway that handles upstream authentication without exposing secrets to page content.

Chrome, Edge and Firefox considerations

Chromium-based browsers share many network behaviors, but Chrome, Edge and Firefox do not expose every authentication path identically. Use Selenium’s standard proxy capability first. Avoid a collection of browser-specific command-line flags unless the capability cannot express a documented requirement.

Choice Best use Important check
Manual HTTP and SSL proxy Normal web UI and HTTPS tests Configure both endpoints and verify CONNECT succeeds
SOCKS proxy Browser flows that explicitly need SOCKS support Set SOCKS version and validate DNS behavior
System proxy Managed desktop environments Document operating-system state and avoid hidden test dependencies
PAC file Organization-controlled routing rules Version the PAC policy and test bypass rules
Direct connection Control run and local application testing Use it as a baseline, not an accidental bypass

For Firefox, attach the same Proxy object to FirefoxOptions. For Edge, use EdgeOptions. Keep framework code small and push environment-specific addresses into configuration so the test logic does not change between local and CI runs.

Selenium authenticated proxy options
Prefer supportable credential paths: IP allowlisting, a managed extension or an approved local gateway.

Authenticated proxies in Selenium

A 407 response means the proxy needs valid authentication. Selenium can express SOCKS username and password in the Proxy object, but browser support and HTTP proxy challenge behavior still need real testing. For private HTTP proxies, the most portable options are usually provider-side IP allowlisting or a managed authentication component under your control.

Option 1: IP allowlisting

Allow the CI runner’s stable public IP in the proxy account, then configure only host and port in Selenium. This avoids placing a password in browser arguments or extension files. It is a strong fit for fixed runners, but not for laptops whose public IP changes frequently.

Option 2: managed browser extension

A Chrome extension can answer proxy authentication challenges, but it becomes a security-sensitive test dependency. Generate it at runtime from a template, restrict its permissions, never commit secrets, and delete the temporary directory after the driver quits. Revalidate the method when browser extension policies change.

Option 3: approved local gateway

A local forwarding service can receive unauthenticated traffic from the isolated test runner and authenticate to the upstream proxy. Bind it to localhost, restrict clients, protect logs and shut it down after the suite. Do not expose an open forwarding port.

The proxy authentication guide compares username/password and IP allowlisting in more detail.

Map WebDriver sessions to proxy sessions

A WebDriver session owns browser state. For account, checkout or multi-page QA, assign one stable proxy for the complete driver lifetime. Starting a new proxy halfway through a session can create location, cookie and risk inconsistencies that make a test fail for reasons unrelated to the application.

  • Allocate the proxy before creating the driver.
  • Verify the exit and expected country at the beginning.
  • Keep one account, browser profile and proxy aligned.
  • Do not share a mutable profile between parallel drivers.
  • Quit the driver before releasing the proxy assignment.
  • Quarantine endpoints that repeatedly fail the same health check.

Selenium Grid adds another layer: the browser node, not necessarily the test client, makes the destination connection. Confirm where the proxy is reachable from and where environment variables are applied. Record the node and proxy IDs in the test report without exposing credentials.

Troubleshoot Selenium proxy failures by layer

Symptom Likely cause Evidence to collect
Driver cannot start Browser/driver mismatch or invalid options Driver logs, versions and minimal direct test
Browser opens but no page loads Proxy host, port, firewall or DNS Proxy tester result and browser error page
407 or login dialog Unsupported or missing proxy credentials Authentication method and masked proxy response
Wrong exit IP Capability not applied or bypass rule matched Capabilities, observed IP and target hostname
Only HTTPS fails SSL proxy, CONNECT or certificate trust Browser error, certificate chain and proxy protocol
Parallel suite is flaky Overload, shared profile or proxy reuse Worker count, assignment log and timing

Do not solve a certificate error with a permanent insecure flag. Investigate the certificate name, trust chain, system clock and any authorized interception. Use the proxy error code guide and proxy tester before changing application assertions.

Selenium proxy failure layers
Separate WebDriver startup, browser networking, proxy response and page assertions before retrying.

Use Selenium proxies for reproducible QA

Regional QA should define the country, browser, viewport, locale, time zone, account state and expected result. The proxy controls the network exit, not every location signal. Test redirects, localized content, consent, prices and forms with the same evidence template used by the website testing guide.

Capture screenshots after important transitions, but add the final URL, observed IP, browser version and expected outcome. A screenshot without context is difficult to reproduce. If the test collects public data, follow the responsible pacing and validation practices in the scraping proxy guide.

Minimal acceptance checklist

  • The driver starts with expected capabilities.
  • The IP-check page shows the assigned proxy exit.
  • The target loads with the expected status and content.
  • The session remains on one proxy through stateful steps.
  • Failures include a screenshot, browser log and masked proxy ID.
  • The driver always quits and temporary credential material is removed.

Selenium, Playwright or Puppeteer?

Use Selenium when broad WebDriver ecosystem support, existing Grid infrastructure or multi-language bindings are central. Choose Playwright when fast context isolation, integrated tracing and per-context proxy configuration fit the suite. Choose Puppeteer for focused Chrome or Firefox automation in a JavaScript codebase.

Do not migrate only because proxy configuration looks shorter in another tool. Compare browser coverage, team language, CI environment, diagnostics and the real test portfolio. A small proof using the same private proxy and target page reveals more than a generic feature table.

Selenium proxy FAQ

How do I set a proxy in Selenium Python?

Create a Selenium Proxy with manual type, set HTTP and SSL endpoints, assign it to the browser Options object, then create the WebDriver with those options.

Does Selenium support proxy username and password?

SOCKS credential fields exist, but portable HTTP proxy authentication is not a universal WebDriver capability. Prefer IP allowlisting or a tested managed authentication method.

Why does Selenium show a proxy authentication dialog?

The browser received a proxy challenge that the configured WebDriver capability did not answer. Verify the authentication method and browser-specific support.

Can every Selenium driver use a different proxy?

Yes. Build separate browser Options and Proxy objects before creating each driver, then keep the assignment stable for that driver session.

How do I verify the proxy works?

Load a controlled IP endpoint at session start, compare the observed address and location with the assigned endpoint, then test the authorized target.

Should Selenium rotate proxies on every page?

No for stateful tests. Assign one stable endpoint for the driver session and rotate only when starting a new independent scenario.

Use tested proxies in reproducible developer workflows

Use private proxies with a documented authentication path, align one endpoint with each stateful WebDriver session, and keep credentials out of capabilities, logs and repositories.

Selenium proxy setup steps

  1. Choose the proxy protocol supported by your Selenium browser session.
  2. Add the proxy host and port to the browser options before starting WebDriver.
  3. Configure username and password authentication or whitelist the testing IP.
  4. Open a neutral IP check page inside the Selenium session.
  5. Only after the exit IP is correct, run the real automated test.

Proxies for Selenium: practical buying notes

This page is strongest when it connects setup details to a buying decision. Use stable private proxies when you need repeatable tests, account-safe sessions, reproducible reports or clean troubleshooting. Use cheaper semi-dedicated proxies for early testing and move important workflows to dedicated IPs once the process is proven.

Need Recommended proxy behavior Related guide
Stable sessions Use static or sticky private proxies. Static vs rotating proxies
Troubleshooting Test format, authentication and exit IP before scaling. Proxy tester
Location-sensitive checks Choose proxy country close to the target audience. Choose proxy location

What proxy type should I start with?

Start with static private proxies when accuracy and troubleshooting matter. Use rotation only when the workflow can tolerate IP changes.

Should I test proxies before using them?

Yes. Test one proxy outside the application first, then import the same working format into the real tool.

Related BuyProxies guides

These related pages help connect the setup, troubleshooting and buying decisions instead of treating each proxy problem in isolation.

Proxy authentication failed

Use this guide as the next step when you need a more specific proxy workflow.

HTTP 407 proxy authentication required

Use this guide as the next step when you need a more specific proxy workflow.

Proxy timeout errors

Use this guide as the next step when you need a more specific proxy workflow.

Best proxies for scraping

Use this guide as the next step when you need a more specific proxy workflow.

How many proxies for scraping

Use this guide as the next step when you need a more specific proxy workflow.

How many proxies for multiple accounts

Use this guide as the next step when you need a more specific proxy workflow.

Scroll to Top