WebDriver automation guide

Selenium Proxy Setup in Python

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

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.

Where should I verify the proxy in a Python Selenium test? Open an IP-check URL inside the WebDriver-controlled browser and inspect the page it loads. A successful requests.get call from the Python process exercises a different client. For a remote browser, make sure the proxy is reachable from the machine running that browser.

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
options.accept_insecure_certs = False

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

What ssl_proxy means for HTTPS requests in Selenium

In Selenium Python, ssl_proxy sets the WebDriver sslProxy entry for HTTPS destinations. For the HTTP proxy in this example, Chrome sends a CONNECT request to the configured host and port, then establishes TLS with the website through that tunnel. The setting does not add TLS to the connection between the browser and the proxy server. Ask the provider which protocol the endpoint itself accepts. WebDriver proxy capability · Chromium HTTP proxy behavior

Pass the local destinations in no_proxy as a list. Keep certificate checking enabled explicitly with accept_insecure_certs = False, especially when adapting the example to FirefoxOptions. If the browser shows a certificate error, check the destination certificate and the trust store on the worker.

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.

How Chrome, Edge and Firefox handle WebDriver proxy settings

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. Keep the proxy address in the test environment so the same script can run locally or in CI.

Set an HTTP proxy in Microsoft Edge with Selenium

Use Selenium 4 with a version of Microsoft Edge WebDriver that matches your browser. If you install the driver manually, the first three parts of its version number must match Edge. See Microsoft’s Edge WebDriver setup.

Keep the manual Proxy object from the Python example. Replace the three lines that create Chrome options and start the driver with these Edge lines.

options = webdriver.EdgeOptions()
options.proxy = proxy
driver = webdriver.Edge(options=options)

Open your IP-check URL in the Edge session and compare the returned IP with the expected exit. Keep the existing finally block so the browser closes after the check.

Edge routing check, November 26, 2026. On Windows, we ran this example in headless Edge 158.0.4370.33 with Selenium 4.53.0. A local HTTP endpoint saw 127.0.0.1 on the direct run and 127.0.0.2 through the test proxy. The proxy recorded one request to that endpoint. Both addresses belong to the local test environment.

Selenium proxy test in Chrome and Firefox

Use the browser session to verify its own network route. Open an IP-check endpoint you control with driver.get(), then compare the address reported by that endpoint with the assigned exit. An HTTP request made separately by the Python test script uses that client’s own proxy configuration.

A Python test script controls WebDriver. Use an IP-check page inside the launched browser to observe its exit IP.
Open the same IP-check URL in the browser for your direct control and your proxied test.

On November 18, 2026, we ran headless Chrome and Firefox on Windows with Selenium WebDriver 4.53.0. The same manual HTTP proxy setting was used for both browsers. A local test server reported the source address of each connection.

Browser Authentication method Source seen by test server
Chrome 157.0.8103.79 HTTP proxy with source IP allowed on localhost 127.0.0.2
Firefox 160.0 HTTP proxy with source IP allowed on localhost 127.0.0.2

In the direct control the server saw 127.0.0.1. Through the test proxy it saw 127.0.0.2 in both browsers, and the proxy recorded one request to the test endpoint for each driver. Both addresses are local to the lab. The check covered plain HTTP routing.

Repeat the check in your test environment

  1. Use an HTTP endpoint you control that returns its connection’s source IP. Open it directly to record a baseline.
  2. Configure an HTTP test proxy that permits your runner’s source IP and has a distinct exit address. For an isolated loopback test, use a reserved hostname such as selenium-proxy-check.test and map it to the local endpoint at the proxy. Have the proxy connect from 127.0.0.2 if that address is available.
  3. Set the manual proxy capability from the Python setup on fresh Chrome and Firefox sessions. Open the test URL from both sessions and compare the returned IP with the proxy’s expected exit. Confirm the requests in the proxy log and quit both drivers.

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.

Which IP should I allowlist for Selenium?

Allowlist the public source IP the proxy provider sees when the browser connects. With a local driver, that is usually the public IP of your workstation or CI runner. With Selenium Grid, use the outbound public IP of the node running the browser, including any NAT gateway in its path.

Check the node’s outbound IP from the browser’s network without the proxy, using an endpoint you control. Then apply the allowlist and check the exit IP inside the proxied WebDriver session. The second check should show the proxy exit.

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. Use the proxy pool recovery criteria before assigning the endpoint to another browser session.

On Grid, verify that the node can reach the proxy before starting the suite. Use the browser node’s outbound IP for allowlisting and record the node and proxy IDs in your test report.

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.

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.

Choose a proxy plan for Selenium tests

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.

Choose Dedicated when the job needs an IP assigned exclusively to your account. Use Semi-Dedicated when the test can use shared exits. Verify the exit and your target site from one worker before adding more browsers.

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.

Verify one proxy in Selenium before running a grid

Start one browser session on the worker that will run the test. Check the exit inside that browser before testing your target application. Repeat the check for each market or worker configuration you plan to use. Choose a consistently assigned exit when the job must meet a fixed IP allowlist.

Diagnose a Selenium proxy connection.

Scroll to Top