How to Use a Proxy with Selenium WebDriver in Python

Ryan
Ryan
IP Proxy Research Team

A Selenium script can control Chrome correctly and still send every browser request through your normal internet connection. If the workflow needs a different network route for regional QA, public-web testing, or another authorized browser task, the proxy has to be attached to the WebDriver session itself and then verified inside that same browser.

Quick Answer

For a proxy that only needs a host and port, set Selenium's Proxy object on ChromeOptions before creating the driver. For a username/password proxy, current Selenium 4 can combine the proxy capability with a WebDriver BiDi authentication handler; Python's high-level BiDi network authentication API was added in Selenium 4.45. After the browser starts, open an IP-check endpoint inside that Selenium session and confirm that the visible IP changed before running the real workflow.

A proxy changes the browser's network route. It does not automatically change cookies, account state, browser fingerprint, device identity, or a website's access policy.

Key Takeaways
  • Configure the proxy before webdriver.Chrome() creates the browser session.
  • Use Selenium's standard Proxy capability for host-and-port routing instead of relying on old driver-manager workarounds.
  • HTTP proxy credentials are a separate problem from proxy routing; do not assume user:pass@host:port will work as a universal Selenium setting.
  • On Selenium 4.45+, WebDriver BiDi can handle authentication challenges programmatically when BiDi is enabled.
  • Verify the route inside the controlled browser, not in a separate browser or terminal.
  • Treat proxy choice as session configuration: when you need another route, creating a new WebDriver session is the clearest pattern.

What a Selenium Proxy Changes

A Selenium proxy changes the network path used by the browser session that WebDriver launches. Requests leave through the configured proxy endpoint, so the destination normally sees the proxy's public IP rather than the public IP of the machine running Selenium.

This setting is narrower than the entire browser environment. A different IP address does not automatically change cookies, account region, language, timezone, WebRTC behavior, device characteristics, or application permissions. That distinction matters when a page still behaves differently after the visible IP has changed.

Selenium's current Browser Options documentation exposes proxy configuration as a WebDriver capability. In Python, the standard path is to create a Proxy object and attach it to the browser options before the session starts.

What You Need Before You Start

Make sure your Selenium setup works before adding proxy routing. If you have not tested the browser session yet, start with the Python Selenium WebDriver setup guide. Once the browser starts normally, you can add the proxy endpoint and verify the visible IP.

Table 1: Proxy details to prepare before starting a Selenium WebDriver session.
Value Example Why it matters
Host proxy.example.com The proxy gateway Selenium will send browser traffic to.
Port 8080 The listening port for the selected proxy protocol.
Protocol HTTP, HTTPS, or SOCKS5 The browser configuration must match the endpoint type your provider supplies.
Username your_username Required when the proxy authenticates with credentials.
Password your_password Used together with the username for an authenticated proxy.
Expected route Country, ASN, or known exit IP Gives you something concrete to compare against after the browser opens.

Do not hard-code production credentials in a repository. Environment variables or a secrets manager make it easier to keep the script reusable without exposing the proxy password.

Set an Unauthenticated Proxy with Selenium

For a proxy that does not require username/password authentication, Selenium's built-in proxy capability is enough. The current Python API exposes manual HTTP, SSL, and SOCKS settings through selenium.webdriver.common.proxy.Proxy.

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.proxy import Proxy, ProxyType

PROXY_SERVER = "proxy.example.com:8080"

proxy = Proxy({
    "proxyType": ProxyType.MANUAL,
    "httpProxy": PROXY_SERVER,
    "sslProxy": PROXY_SERVER,
})

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

driver = webdriver.Chrome(options=options)

try:
    driver.get("https://httpbin.org/ip")
    print(driver.find_element(By.TAG_NAME, "body").text)
finally:
    driver.quit()

The same endpoint is used above for HTTP and HTTPS destination traffic. If your provider gives different endpoints or protocols, use the values supplied for that account rather than assuming one host and port applies to everything.

Chrome-Only Shortcut: --proxy-server

Chrome also accepts a proxy server through a command-line argument. This is convenient for a simple host-and-port proxy, but it does not solve username/password authentication by itself.

from selenium import webdriver

options = webdriver.ChromeOptions()
options.add_argument("--proxy-server=http://proxy.example.com:8080")

driver = webdriver.Chrome(options=options)

For reusable Selenium code, the standard Proxy capability is easier to reason about because the network setting lives with the WebDriver options instead of a browser-specific command-line flag.

Verify the Proxy Inside the Selenium Browser

A proxy setup is not confirmed until the controlled browser shows the expected route. Run the check inside the same Selenium session because a proxy configured for WebDriver does not automatically apply to your normal browser, terminal, or another Python HTTP client.

driver.get("https://httpbin.org/ip")

visible_ip = driver.find_element(By.TAG_NAME, "body").text
print(visible_ip)

Compare the returned IP with your direct connection or the route information supplied by the proxy service. If the IP remains unchanged, check the active Selenium options before changing unrelated browser settings.

For a broader validation workflow, IPWeb's guide on how to check if a proxy is working explains how to compare the visible IP, country, ISP, ASN, protocol, and test environment. The important rule is the same: test in the exact browser or application where the proxy is configured.

Use an Authenticated Proxy with WebDriver BiDi

Username/password proxy authentication is separate from setting the proxy address. Selenium's HTTP and SSL proxy fields define where traffic should go, but they do not expose generic HTTP proxy username and password fields. Current WebDriver BiDi provides a cleaner way to answer the authentication challenge after the proxy requests credentials.

Chrome authentication prompt for a proxy in a Selenium-controlled browser
Figure 1: A Selenium-controlled Chrome session can display an authentication prompt when the configured proxy requires credentials. Source: Avishka Perera on Stack Overflow, CC BY-SA 3.0.

Python gained high-level BiDi network request, response, and authentication handlers in Selenium 4.45. The current API exposes driver.network.add_auth_handler(username, password). WebDriver BiDi's network specification treats both normal HTTP authentication and a 407 Proxy Authentication Required response as authentication challenges.

Update Selenium before using this approach:

python -m pip install -U selenium

Then enable BiDi, attach the proxy route, register the authentication handler, and navigate only after the handler is ready:

import os

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.proxy import Proxy, ProxyType

PROXY_HOST = "proxy.example.com"
PROXY_PORT = "8080"
PROXY_USERNAME = os.environ["PROXY_USERNAME"]
PROXY_PASSWORD = os.environ["PROXY_PASSWORD"]

proxy = Proxy({
    "proxyType": ProxyType.MANUAL,
    "httpProxy": f"{PROXY_HOST}:{PROXY_PORT}",
    "sslProxy": f"{PROXY_HOST}:{PROXY_PORT}",
})

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

driver = webdriver.Chrome(options=options)
auth_handler_id = driver.network.add_auth_handler(
    PROXY_USERNAME,
    PROXY_PASSWORD,
)

try:
    driver.get("https://httpbin.org/ip")
    print(driver.find_element(By.TAG_NAME, "body").text)
finally:
    driver.network.remove_auth_handler(auth_handler_id)
    driver.quit()

This example targets current Selenium with WebDriver BiDi enabled. BiDi support is still evolving across browsers and remote environments, so test the exact browser, Selenium version, and Grid or CI configuration you plan to use before treating the setup as production-ready.

If your proxy service supports source-IP allowlisting, that can be simpler in a server or CI environment with a stable public egress IP because the browser does not need to answer a credential challenge. IP allowlisting and proxy username/password authentication authorize different parts of the connection; the IP allowlisting guide explains the distinction.

Use an IPWeb Proxy Endpoint

An IPWeb proxy string may be presented in the form host:port:username:password. For Selenium, split those values instead of pasting the entire four-part string into httpProxy.

IPWeb residential proxy dashboard for generating proxy configuration settings
Figure 2: The IPWeb Get Proxy page provides location and protocol controls used to generate proxy configuration details for a browser session.
gate1.ipweb.cc:7778:your_username:your_password

That example maps to:

Table 2: Mapping an IPWeb proxy string to Selenium configuration values.
Field Value
Proxy host gate1.ipweb.cc
Proxy port 7778
Username your_username
Password your_password

Use the host and port in Selenium's proxy capability, then supply the username and password through the authentication method that fits the environment. Keep real credentials in environment variables rather than in screenshots, source control, or published code.

What About SOCKS5 Proxies?

Selenium's Python proxy API also exposes SOCKS settings, including SOCKS username, password, and version fields. A SOCKS5 configuration can look like this:

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

proxy = Proxy({
    "proxyType": ProxyType.MANUAL,
    "socksProxy": "proxy.example.com:1080",
    "socksVersion": 5,
    "socksUsername": "your_username",
    "socksPassword": "your_password",
})

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

driver = webdriver.Chrome(options=options)

Browser and provider behavior can differ, especially around SOCKS authentication, DNS handling, and remote WebDriver environments. Confirm that SOCKS5 is enabled for the endpoint and verify the visible route before building the rest of the workflow.

Rotate Proxies Between Selenium Sessions

When you need a different route, the clearest pattern is to create a new WebDriver session with a new proxy configuration. The proxy capability is supplied when the browser session is created, so session-level rotation keeps the code predictable and avoids trying to mutate a live browser's network setup.

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.proxy import Proxy, ProxyType

proxy_servers = [
    "proxy-a.example.com:8080",
    "proxy-b.example.com:8080",
    "proxy-c.example.com:8080",
]

for proxy_server in proxy_servers:
    proxy = Proxy({
        "proxyType": ProxyType.MANUAL,
        "httpProxy": proxy_server,
        "sslProxy": proxy_server,
    })

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

    driver = webdriver.Chrome(options=options)

    try:
        driver.get("https://httpbin.org/ip")
        print(driver.find_element(By.TAG_NAME, "body").text)
    finally:
        driver.quit()

Do not rotate simply because rotation is available. A multi-step workflow may need the same exit route for the whole browser session, while a regional comparison may intentionally use separate sessions for different routes. If the proxy provider offers gateway-managed rotation or sticky sessions, use those session rules instead of inventing client-side switching logic.

Which Proxy Type Fits a Selenium Workflow?

The better proxy type depends on whether the Selenium workflow needs route diversity, session continuity, or a simple infrastructure-level connection. Choose based on the browser task rather than assuming one proxy category is best for every script.

Table 3: Proxy-route choices for common Selenium testing and browser-automation workflows.
Workflow Route style Why it fits What to watch for
Regional QA or public-page comparison Residential route with location and session controls Useful when separate sessions need different approved country or city routes. Keep locale, cookies, and account state separate from the IP result.
Short independent browser jobs Rotating or short sticky sessions Lets each new browser task start with a controlled route. Verify whether the provider rotates by request, session, or credential rule.
Long multi-step test Stable or sticky route Keeps the same egress path while the browser moves through several steps. Do not change the route halfway through a workflow that depends on continuity.
Internal or infrastructure QA Datacenter or organization-managed proxy Often simpler when the goal is controlled network routing rather than residential location. Confirm firewall, authentication, and corporate policy requirements.

For authorized regional checks and public-web workflows that need location targeting plus rotating or sticky session controls, IPWeb Dynamic Residential Proxies support HTTP, HTTPS, and SOCKS5 endpoints. Start with a small route check in Selenium before increasing the number of browser sessions.

Common Selenium Proxy Errors

Proxy failures become easier to diagnose when routing, authentication, browser startup, and page timing are treated as separate layers. Increasing a timeout will not fix a wrong password, and changing proxy providers will not fix a Selenium session that never received the proxy setting.

Chrome ERR_PROXY_CONNECTION_FAILED error in a Selenium-controlled browser
Figure 3: ERR_PROXY_CONNECTION_FAILED indicates that Chrome could not establish a connection to the configured proxy endpoint. Source: Seif Fahmy on Stack Overflow, CC BY-SA 4.0.
Table 4: Common Selenium proxy failures and the first check to make.
Problem Likely Cause How to Check What to Do Next
407 Proxy Authentication Required Credentials are missing, wrong, or the auth handler was not active before navigation. Confirm username/password values and whether BiDi is enabled. Register the authentication handler before the first proxied navigation.
ERR_PROXY_CONNECTION_FAILED Wrong host, port, protocol, unreachable gateway, or blocked outbound connection. Recheck the endpoint and test whether the machine can reach the proxy gateway. Correct the endpoint or network rule before debugging Selenium locators.
Your normal IP still appears The proxy was not applied to the WebDriver session being tested. Open the IP test inside the same controlled browser window. Inspect options.proxy and create a new driver after correcting it.
Navigation times out Slow route, unavailable proxy, slow target, or page-load behavior. Test the proxy against a simple IP endpoint before the target page. Separate network latency from element waits and page-specific loading issues.
Selenium Manager cannot obtain ChromeDriver The machine cannot reach Selenium's driver metadata or download endpoints. Check Selenium Manager logs and the machine's outbound network path. Use a current Selenium version and configure Selenium Manager's own proxy with SE_PROXY when required.
IP changes but page behavior does not The page may also depend on cookies, account settings, language, timezone, or application policy. Confirm the route first, then inspect non-IP state separately. Do not assume another proxy will fix a non-network cause.

If the proxy route is working but Selenium still tries to use an element before it is ready, handle that separately with an explicit wait. See the Selenium WebDriverWait guide for condition-based waits and timing issues.

When Selenium Manager Needs Its Own Proxy

Selenium Manager may need network access before the browser session exists so it can discover or download a compatible driver. Its current configuration supports an HTTP proxy through the SE_PROXY environment variable, including an authenticated value such as myuser:mypass@myproxy:port.

# Linux / macOS
export SE_PROXY="myuser:mypass@myproxy:port"

# Windows PowerShell
$env:SE_PROXY="myuser:mypass@myproxy:port"

This setting is for Selenium Manager's own network connection. It is separate from the proxy capability used by the Chrome session you create afterward.

Practical Selenium Proxy Checklist

Before running the real browser workflow
  • Confirm Selenium and the browser start normally without the proxy first.
  • Copy the proxy host, port, protocol, and authentication method exactly.
  • Attach the proxy to ChromeOptions before creating webdriver.Chrome().
  • For an authenticated HTTP proxy on current Selenium, enable BiDi and register the auth handler before navigation.
  • Keep usernames and passwords in environment variables or a secrets manager.
  • Open an IP-check endpoint inside the same Selenium browser session.
  • Confirm the visible IP and expected country or network before testing the target page.
  • Use a new WebDriver session when you deliberately need a different route.
  • Troubleshoot proxy routing before changing locators, waits, or page logic.

Frequently Asked Questions

Does Selenium support proxies natively?
Yes. Selenium WebDriver exposes a standard proxy capability, and the Python bindings provide the Proxy class for manual HTTP, SSL, SOCKS, PAC, system, and other supported proxy modes. Configure it on the browser options before the WebDriver session starts.
Can Selenium pass a proxy username and password directly?
Selenium's generic HTTP and SSL proxy fields do not provide separate username and password properties. On current Selenium 4, WebDriver BiDi can handle authentication challenges programmatically when BiDi is enabled. Provider-supported source-IP allowlisting is another option when the environment has a stable public IP.
Should I use Selenium Wire for proxy authentication?
It is no longer a good default for a new project. The Selenium Wire GitHub repository was archived in January 2024 and states that the project is no longer maintained. Existing projects may still use it, but new Selenium code should prefer supported Selenium features or another maintained approach.
Can Selenium use a SOCKS5 proxy?
Yes. Selenium's Python proxy API includes SOCKS proxy, version, username, and password fields. Browser and provider behavior can still vary, so verify that the endpoint supports SOCKS5 and test the visible route in the same WebDriver session.
How do I know Selenium is actually using the proxy?
Open an IP-check endpoint inside the browser controlled by Selenium and compare the visible IP with your direct connection or expected proxy route. Testing in another browser does not validate the Selenium session.
Can I change the Selenium proxy without restarting Chrome?
Treat the normal WebDriver proxy capability as session-start configuration. When you deliberately need another route, creating a new driver with the new proxy is the simplest predictable pattern. Provider-managed sticky or rotating gateways may change the exit route according to their own session rules without rewriting Selenium options.
Why do I still get a 403 after the proxy IP changes?
A changed IP only confirms the network route. A 403 can come from authentication, application permissions, request state, account rules, a CDN or WAF, or another server-side policy. Diagnose the response instead of assuming more proxy rotation will solve it.

Final Thoughts

A reliable Selenium proxy setup has four separate steps: configure the route, handle authentication when required, verify the visible IP inside the same WebDriver session, and only then run the browser workflow. Current Selenium makes the first step straightforward with the standard Proxy capability, while newer WebDriver BiDi network APIs give Python a maintained path for authentication challenges.

Keep proxy routing in its proper scope. It can change the network path used by Selenium, but it cannot guarantee that a website will accept the connection or override account, application, legal, or platform-level rules. When a test fails after the route is confirmed, inspect the actual browser and response state before changing the proxy again.

About the author
View all articles
Ryan
Ryan
IP Proxy Research Team

Ryan is a web data and proxy infrastructure specialist focused on IP networks, scraping systems, SERP APIs, and global data access solutions. He shares practical insights on proxy usage, data collection architecture, and scalable web intelligence systems.

Service areas
Proxy IP Web Scraping & Data Infrastructure Specialist

You may be interested in

Virtual Browser vs Virtual Machine cover comparing a cloud browser environment with a full virtual machine for web testing

Virtual Browser vs Virtual Machine: Which Is Better for Web Testing?

A browser-specific bug can disappear when the browser version, operating system, or network path changes. That makes the test environment part of the evidence. A virtual browser can give you fast access to another browser or browser-and-OS combination, while a virtual machine gives you control over an entire guest operating system. The terms overlap, but they are not interchangeable. In web testing, virtual browser is best treated as an access model: you receive a browser session that runs in a provider-managed or isolated environment. The underlying session may run on a VM, container, real machine, or device depending on the...

Ryan

Ryan

IP Proxy Research Team

Inspect Element on Mac cover showing Chrome DevTools on a MacBook with Chrome, Safari, and Firefox support

How to Inspect Element on Mac and Check Page Data

On a Mac, you can inspect a webpage in Chrome, Safari, or Firefox from the context menu or with a keyboard shortcut. Opening DevTools is only the first step: the Elements and Network panels can also show whether a visible field is already in the page HTML, added after JavaScript runs, or returned by a separate request. Use the browser and page state that match the task you are checking. A product price, search result, listing, or other public field can appear differently before and after filters, pagination, or client-side rendering. Quick Answer To Inspect Element on a Mac, Control-click...

Ryan

Ryan

IP Proxy Research Team

Python Selenium WebDriver: Setup and Checks

Python Selenium WebDriver: Setup and Checks

Setting up Selenium WebDriver with Python is simpler than many older tutorials suggest. Install the Selenium package, make sure a supported browser such as Chrome is available, then create a WebDriver session and verify that the browser can load and interact with a known page. Quick Answer Install Selenium with python -m pip install -U selenium, then start Chrome with webdriver.Chrome(). In modern Selenium, Selenium Manager usually handles driver discovery or download automatically when you do not provide a driver yourself. After the browser opens, confirm the URL, title, and a known element, then close the session with driver.quit(). Add...

Ryan

Ryan

IP Proxy Research Team

Ready to scale your data operations?
Join 10,000+ teams using IPWeb to power their web data collection. Start free today.

Strictly anti-abuse

Fraud, automated operation, and unauthorized use are prohibited.

Enterprise-level services

For legitimate commercial and technical use cases only

Risk control and restrictions

Abnormal behavior may trigger service restrictions or termination.

Compliance data use

Data acquisition and use must comply with relevant regulations.

Privacy protection first

The collection or misuse of sensitive personal information is strictly prohibited.

All services are subject to《the Usage Policy》