Skip to content

How to Set Up a Proxy in Selenium for QA Work

A practical guide to routing Selenium WebDriver sessions through a proxy for regional and environment testing, with Chrome and Firefox examples and a verification routine.

9 min readUpdated Nov 13, 2026By XPASS Editorial Team

How to Set Up a Proxy in Selenium for QA Work

Selenium is still one of the most common ways to run browser-based quality assurance, and sooner or later a QA team needs a test to leave the office network. You may want to see how a landing page behaves for a visitor in another country, check that a staging firewall lets a known address through, or reproduce a bug that only appears behind a corporate gateway. In each case the answer is the same: send the browser traffic through a proxy. This guide explains how to do that cleanly with Selenium WebDriver, which options exist for Chrome and Firefox, how to deal with authentication, and how to prove that the traffic really takes the path you intended.

Everything here assumes lawful use. Run these tests against your own properties, staging systems, or sites where you have written permission, respect the terms of service and any robots.txt rules, and keep request volume modest. A proxy changes the route of your traffic, not your obligations.

What a proxy does inside a Selenium session

When Selenium starts a browser, the browser makes its own network connections. Selenium only sends commands to the driver, which then controls the browser. That means a proxy has to be configured on the browser, not on the Selenium client library. The browser then sends its page requests to the proxy, and the proxy forwards them to the destination site. The destination sees the proxy address as the visitor, which is exactly what you want when testing regional behavior.

Two proxy families matter for QA work. An HTTP proxy understands web traffic; for HTTPS sites the browser asks it to open a tunnel with the CONNECT method and then runs TLS end to end through that tunnel, as described in the MDN overview of proxy servers and tunneling. A SOCKS5 proxy works one level lower and relays arbitrary TCP connections, as defined in RFC 1928. Both are supported by Chrome and Firefox. HTTP proxies are the simpler default for web testing, and SOCKS5 is useful when your provider offers it or when you also want the browser DNS lookups to go through the proxy.

Before you write any code, collect four facts from your provider's dashboard or the proxy product page: the host name or IP address, the port, the protocol (HTTP or SOCKS5), and the authentication method (username and password, or an allowlist of your source IP address). The rest of this guide uses placeholder values such as proxy.example.net:8080.

Configuring Chrome

For Chrome, the most direct approach is the --proxy-server argument. In Python it looks like this:

from selenium import webdriver

options = webdriver.ChromeOptions()
options.add_argument("--proxy-server=http://proxy.example.net:8080")
driver = webdriver.Chrome(options=options)
driver.get("https://staging.example.com/")

For SOCKS5 change the scheme to socks5://. When you use a SOCKS5 proxy in Chrome, the host name lookup is normally performed by the proxy, which is helpful when you want the target site resolved from the proxy side.

You can exclude addresses from proxying with --proxy-bypass-list, a semicolon-separated list such as localhost;127.0.0.1;*.internal.example.com. This matters in QA because many test suites also talk to a local mock server, a test database admin page, or an internal reporting endpoint. If those requests are accidentally sent to an external proxy they will fail or, worse, leak internal host names to a third party.

Chrome has one well-known limitation: it does not accept a username and password inside the --proxy-server value. If you write http://user:pass@host:8080, the credentials are not used. The next section covers practical ways around this.

The same options object works in Java and JavaScript with the equivalent method for adding browser arguments. Selenium 4 also lets you set a browser-neutral Proxy object on the options, which is covered later.

Configuring Firefox

Firefox does not use command-line flags for the proxy. Instead you set preferences. In Python:

from selenium import webdriver

options = webdriver.FirefoxOptions()
options.set_preference("network.proxy.type", 1)  # 1 = manual configuration
options.set_preference("network.proxy.http", "proxy.example.net")
options.set_preference("network.proxy.http_port", 8080)
options.set_preference("network.proxy.ssl", "proxy.example.net")
options.set_preference("network.proxy.ssl_port", 8080)
options.set_preference("network.proxy.no_proxies_on", "localhost,127.0.0.1")
driver = webdriver.Firefox(options=options)

Note that HTTPS traffic uses the separate network.proxy.ssl pair, so set both. For SOCKS5, set network.proxy.socks, network.proxy.socks_port, network.proxy.socks_version to 5, and consider network.proxy.socks_remote_dns set to true so name resolution happens on the proxy side.

Firefox also has a quirk worth knowing: by default it does not proxy requests to localhost or 127.0.0.1, even when a manual proxy is set, which usually suits QA work. If you ever need it to, you must clear the relevant preference deliberately.

Using the browser-neutral Proxy object

Selenium 4 offers a Proxy class that translates into the right capability for each browser. It is handy when one test suite runs in several browsers.

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

proxy = Proxy()
proxy.proxy_type = ProxyType.MANUAL
proxy.http_proxy = "proxy.example.net:8080"
proxy.ssl_proxy = "proxy.example.net:8080"
proxy.no_proxy = "localhost,127.0.0.1"

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

The same options.proxy = proxy line works with Firefox options. Keep in mind that the exact attribute names differ slightly between language bindings, so check the binding you use. For a SOCKS proxy set socks_proxy and socks_version instead of the HTTP fields.

Handling authentication

Many providers authenticate in one of two ways, and the choice changes how you set up Selenium.

The first is IP allowlisting. You register the public IP address of the machine or CI runner that runs the tests, and the proxy then accepts connections from it without a password. This is the least fragile option for Selenium because no credentials ever need to pass through the browser. Its weak point is that cloud CI runners often change address, so you need either a fixed egress address or a step that updates the allowlist.

The second is username and password. Because Chrome ignores credentials in the flag, teams typically choose one of these patterns:

Pattern How it works Trade-off
Local forwarding proxy A small proxy on 127.0.0.1 adds the credentials and forwards upstream; Chrome points to the local port One extra process to run and secure
Browser extension A small extension answers the proxy authentication challenge Needs extension packaging and a non-headless or new-headless mode
Driver-level auth handler Selenium 4 with a Chromium driver can register credentials through the DevTools or BiDi network interface Depends on binding and version
Allowlist No credentials at all Requires stable source IP address

Whatever you choose, keep credentials out of the repository. Read them from environment variables or your CI secret store, and never print them into test logs or screenshots.

Verifying the route

A misconfigured proxy is dangerous because the tests may still pass. The browser can silently fall back to a direct connection in some setups, and you would then be certifying behavior from the wrong location. Make verification part of the suite.

  1. At the start of the run, load a page or API that returns the caller's public IP address, for example one you host yourself or a neutral echo service your team already uses.
  2. Compare the result with the address of the test machine without a proxy. Assert that they differ and, if your provider documents the expected exit region, that the reported region matches.
  3. Record the observed address in the test report so that a failing test can be traced to the exact exit used.
  4. Repeat the check if the session is long, because some rotating setups change the exit address on a schedule.

A simple pytest fixture can do this once per session:

import pytest

@pytest.fixture(scope="session")
def proxied_driver():
    driver = build_driver_with_proxy()
    driver.get("https://ip-echo.example.com/")
    seen = driver.find_element("tag name", "body").text.strip()
    assert seen != DIRECT_IP, "Traffic is not going through the proxy"
    yield driver
    driver.quit()

Here ip-echo.example.com and DIRECT_IP are placeholders for your own echo endpoint and the address you measured directly.

A plain example: checking a regional banner

Suppose your marketing site shows a cookie banner and a local-language banner depending on the visitor's country. The QA question is whether a visitor from Germany sees the correct text. The steps are:

  1. Obtain an HTTP proxy endpoint that exits in the target country, from your provider.
  2. Start Chrome with --proxy-server pointing to it, and clear cookies at the start of the test.
  3. Open the staging URL and wait for the banner element with an explicit wait instead of a fixed sleep.
  4. Assert on the banner text and on the language attribute of the page.
  5. Run the same test without a proxy and confirm the banner differs, which proves the geo logic is being exercised and not a cached default.

Keep one browser profile per exit region. Reusing a profile with cookies or local storage saved from another region can make the site remember the earlier country and hide the bug you are looking for.

Limits and what to watch for

  • Latency and timeouts. Traffic now takes an extra hop, so page loads are slower than direct. Raise page-load and script timeouts for proxied suites instead of globally weakening your assertions, and prefer explicit waits.
  • Certificates. A normal forwarding proxy tunnels HTTPS without reading it. If your team uses an intercepting proxy, the browser will show certificate errors unless the proxy's root certificate is trusted in the test profile. Do that only in test environments you control.
  • Parallel runs. Many sessions through one endpoint can exceed the connection limits of your plan. Check the plan page for what is included, and size your parallelism accordingly.
  • Rate and politeness. Automation can generate far more requests than a human. Throttle your tests, avoid hammering third-party sites, and stop if the site signals that it does not want automated traffic.
  • Flaky exits. Rotating proxies can change address mid-test, which breaks flows that depend on a stable session. For login or checkout tests prefer a sticky or dedicated address if your provider offers one.
  • Local traffic. Remember the bypass list so that your own test infrastructure does not go through the proxy.
  • Headless differences. Some authentication workarounds that rely on extensions behave differently in headless mode, so test your chosen approach in the same mode that CI uses.

Troubleshooting checklist

If the browser shows ERR_PROXY_CONNECTION_FAILED or a similar message, work through the list in order. Confirm the host and port by testing with curl --proxy from the same machine. Check whether the scheme matches (HTTP versus SOCKS5). Confirm that your source IP address is allowlisted if you rely on that method. Look for a corporate firewall blocking outbound traffic to the proxy port. If pages load but are very slow, test the proxy with a plain command-line request to separate network latency from browser overhead. If only HTTPS fails, make sure Firefox has the ssl preference set and that Chrome is not being forced to use an old policy file that overrides your flag.

If your tests need a SOCKS5 or HTTP endpoint, the same setup logic applies when you move to other tools. The article on using a proxy with Puppeteer in Node.js covers the equivalent Chrome flags from JavaScript, setting up a proxy in Playwright shows a more convenient built-in credentials option, and using a proxy with Scrapy explains the same ideas for permitted public data collection.

Summary

To use a proxy in Selenium, configure it on the browser: the --proxy-server argument in Chrome, the network.proxy.* preferences in Firefox, or the browser-neutral Proxy object in Selenium 4. Prefer IP allowlisting or a local forwarding proxy when you need authentication, because Chrome does not read credentials from the flag. Keep a bypass list for local services, store secrets outside the repository, and verify the exit address at the start of every run so that you never certify behavior from the wrong location. Finally, stay within the law, the site's terms and a polite request rate. When you are ready to choose an endpoint, the details of what each plan includes are on the proxy page.

Frequently asked questions

How do I tell Selenium to use a proxy?

Pass the proxy to the browser through its options. For Chrome that is the --proxy-server argument, and for Firefox it is the network.proxy preferences. Selenium also offers a Proxy object that sets the same values in a browser-neutral way.

Can I put a username and password into the Chrome proxy flag?

No. Chrome ignores credentials in --proxy-server. The usual choices are to allowlist the IP address of your test machine with the provider, to use a local forwarding proxy that adds the credentials, or to use a browser extension or a driver feature that answers the authentication prompt.

How can I confirm that the browser really uses the proxy?

Open a page that echoes the visitor IP address from inside the test, compare it with the address you see without the proxy, and assert on the difference. Do this at the start of every run so a silent misconfiguration is caught early.

Is it acceptable to use a proxy for QA testing?

Yes, when you test your own sites or sites where you have permission, you follow the terms of service and local law, and you keep your request rate polite. A proxy is a routing tool and does not replace authorization.

About the author

Bob Kanokphon Thongdee, founder of XPASS VPN

Bob Kanokphon Thongdee

  • Founder of XPASS VPN
  • Co-founder of eSIMonline.asia
  • More than 7 years in online marketing
  • Founder of Cojourney Visa and Cojourney Travel

Need a proxy for this?

XPASS Proxy sells residential proxy traffic by the gigabyte, with the price shown before you pay.

See proxy plans

Keep reading

Proxy Guides

How to Use a Proxy with Puppeteer in Node.js

A step-by-step guide to routing Puppeteer through a proxy in Node.js, including authentication, excluding hosts, verifying the IP and avoiding common mistakes.

9 min read

Proxy Guides

How to Use a Proxy with Scrapy for Permitted Public Data

Learn how to route Scrapy spiders through a proxy for public data you are allowed to collect, using request meta, a downloader middleware and polite crawl settings.

10 min read

Proxy Guides

How to Set Up a Proxy in Playwright for Website Testing

Learn where Playwright accepts proxy settings, how to pass credentials safely, how to exclude hosts, and how to confirm a test really runs through the proxy.

9 min read