Proxy servers help Selenium tests when traffic needs to be routed, requests monitored, or region-specific behavior validated. With a proxy in place, testers can mask IP addresses, bypass firewalls, and capture network data during browser automation.
Working with proxies in Selenium is not only about enabling redirection. Testers must also handle authentication methods, configure WebDriver correctly, and deal with the practical issues that arise in real test environments.
This article explains the different types of Selenium proxy, authentication methods, setup steps in WebDriver, implementation approaches, and common challenges.
A proxy in Selenium is a server that sits between the test browser and the target application. It routes requests and responses, allowing testers to control and inspect network traffic during automated runs. Using a proxy helps when tests need to simulate users from different regions, apply security rules, or capture HTTP data for debugging.
In Selenium, proxies are configured at the WebDriver level. Once set, every request made by the browser goes through the proxy before reaching the destination server. This gives testers a central point to manage restrictions, authentication, and logging.
Selenium does not restrict you to a single kind of proxy. Depending on the network setup and the type of application under test, you may need different proxy configurations. Each type changes how traffic flows between the WebDriver-controlled browser and the destination server. Here are the main types and their specific testing use cases:
This proxy only supports unencrypted HTTP requests. Since it does not perform SSL/TLS handshakes, it is faster but less secure. In Selenium, it is often used in internal or staging environments where encryption is not required but you still need to capture or reroute traffic.
For example, QA teams may run regression suites through an HTTP proxy to log all requests for debugging without worrying about certificate validation.
This proxy handles encrypted HTTPS traffic. To make Selenium work with it, the WebDriver or the underlying browser must be configured to trust the proxy’s SSL certificate. Without this, you will see certificate validation errors and failed requests.
HTTPS proxies are required in realistic test setups that mirror production security conditions. They allow testers to analyze secure traffic while keeping encryption intact.
Unlike HTTP or HTTPS proxies, a SOCKS proxy works at the transport layer and can forward multiple types of traffic, including HTTP, HTTPS, FTP, and even UDP.
In Selenium, this becomes important when the application uses WebSockets or API calls in parallel with standard web requests. SOCKS proxies are also widely used for geo-testing. By tunneling all browser traffic through a proxy server located in another country, teams can validate how content is served to users in different regions.
A transparent proxy does not require browser-level configuration and forwards traffic without altering headers or enforcing authentication. While it is less common in Selenium test execution, it is valuable in compliance-driven environments.
For example, financial institutions may run tests behind a transparent proxy to keep an audit log of all browser activity without interfering with the test flow. Since the browser is unaware of the proxy, there is no need for additional setup in Selenium scripts.
When you configure Selenium with a proxy, authentication is often required to allow the browser traffic through. There are two common approaches: username-password credentials or IP whitelisting. Both methods achieve the same goal but differ in how they are applied and maintained.
Here are the key differences between username-password vs IP whitelist in Selenium Proxy authentication.
Selenium WebDriver lets you configure proxies directly in the browser session before any test runs. The approach is consistent across browsers, but the exact steps vary depending on the driver and language bindings. In practice, the setup always involves three actions:
Once configured, every request from Selenium will be routed through the proxy server. This makes it possible to monitor, restrict, or redirect traffic as needed.
The next two sections explain how to implement proxies in Selenium, first without authentication and then with authentication.
When the proxy does not require credentials, configuration is straightforward. Set the proxy host and port, attach the proxy to the browser capabilities or options, then start the browser. Below are concrete steps, practical tips, and working examples in Python and Java.
Prelude: do these three things in order. First set the proxy address and type. Second, attach the proxy to the browser capabilities or options. Third, launch the WebDriver session and validate the traffic is routed through the proxy.
Here are the practical steps you will follow:
Below are ready-to-run examples.
Python (Selenium 4) — Chrome and Firefox
# Python example using Proxy.add_to_capabilities
from selenium import webdriver
from selenium.webdriver.common.proxy import Proxy, ProxyType
# 1. proxy address
proxy_host = "10.20.30.40:3128"
# 2. build proxy object
proxy = Proxy()
proxy.proxy_type = ProxyType.MANUAL
proxy.http_proxy = proxy_host
proxy.ssl_proxy = proxy_host
# if using SOCKS:
# proxy.socks_proxy = "10.20.30.40:1080"
# proxy.socks_version = 5
# 3. add to capabilities
capabilities = webdriver.DesiredCapabilities.CHROME.copy()
proxy.add_to_capabilities(capabilities)
# 4. launch Chrome with proxy
driver = webdriver.Chrome(desired_capabilities=capabilities)
driver.get("https://ifconfig.me") # or another IP-check endpoint
print(driver.title)
driver.quit()
# For Firefox, reuse the same capabilities approach
capabilities_ff = webdriver.DesiredCapabilities.FIREFOX.copy()
proxy.add_to_capabilities(capabilities_ff)
driver_ff = webdriver.Firefox(desired_capabilities=capabilities_ff)
driver_ff.get("https://ifconfig.me")
driver_ff.quit()
Notes for Python:
Java — Chrome and Firefox
// Java example using org.openqa.selenium.Proxy and ChromeOptions
import org.openqa.selenium.Proxy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.CapabilityType;
public class ProxyExample {
public static void main(String[] args) {
String proxyAddr = "10.20.30.40:3128";
Proxy proxy = new Proxy();
proxy.setProxyType(Proxy.ProxyType.MANUAL);
proxy.setHttpProxy(proxyAddr);
proxy.setSslProxy(proxyAddr);
// for SOCKS: proxy.setSocksProxy("10.20.30.40:1080"); proxy.setSocksVersion(5);
ChromeOptions options = new ChromeOptions();
options.setCapability(CapabilityType.PROXY, proxy);
WebDriver driver = new ChromeDriver(options);
driver.get("https://ifconfig.me");
System.out.println(driver.getTitle());
driver.quit();
}
}
Notes for Java:
Some proxies do not allow traffic without credentials. In such cases, Selenium needs to send a username and password before the browser session can proceed. There are two main ways to achieve this: by embedding the credentials directly in the proxy URL or by handling authentication prompts programmatically. Both approaches come with trade-offs in security and maintainability.
Here are the common methods you can use:
1. Embed credentials in the proxy URL
This is the simplest method. The proxy address is written in the form username:password@host:port. While easy to configure, this method can expose credentials in logs or stack traces.Python Example:
Python Example:
from selenium import webdriver
from selenium.webdriver.common.proxy import Proxy, ProxyType
proxy = Proxy()
proxy.proxy_type = ProxyType.MANUAL
proxy.http_proxy = "user:pass@10.20.30.40:3128"
proxy.ssl_proxy = "user:pass@10.20.30.40:3128"
capabilities = webdriver.DesiredCapabilities.CHROME.copy()
proxy.add_to_capabilities(capabilities)
driver = webdriver.Chrome(desired_capabilities=capabilities)
driver.get("https://ifconfig.me")
driver.quit()
Java Example:
import org.openqa.selenium.Proxy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.CapabilityType;
public class AuthProxyExample {
public static void main(String[] args) {
String proxyAuth = "user:pass@10.20.30.40:3128";
Proxy proxy = new Proxy();
proxy.setHttpProxy(proxyAuth);
proxy.setSslProxy(proxyAuth);
ChromeOptions options = new ChromeOptions();
options.setCapability(CapabilityType.PROXY, proxy);
WebDriver driver = new ChromeDriver(options);
driver.get("https://ifconfig.me");
driver.quit();
}
}
2. Handle browser authentication pop-ups
Some proxies trigger a login prompt instead of allowing credentials in the URL. Selenium cannot directly interact with these dialogs, so the workaround is to use browser profiles or extensions that inject credentials automatically.
3. IP-based fallback
If authentication prompts cannot be bypassed reliably in automation, some teams combine username-password proxies with IP whitelisting for CI pipelines. This avoids the prompt entirely when tests are executed from trusted infrastructure.
Working with proxies in Selenium is useful but often introduces technical hurdles. Below are the most frequent challenges you will encounter:
Configuring proxies in Selenium gives testers the ability to control how browser traffic is routed, inspected, and authenticated. From choosing the right proxy type to handling authentication methods and troubleshooting issues, every detail matters for keeping tests stable and reflective of real user conditions.
While local proxy setups are useful for controlled environments, running Selenium tests on BrowserStack provides a more scalable option. BrowserStack offers built-in support for proxy configurations, cloud infrastructure with fixed IP ranges, and real device coverage. This allows teams to run reliable cross-browser tests without maintaining proxy servers or debugging complex network issues on local grids.
Run Selenium Tests on Cloud
Get visual proof, steps to reproduce and technical logs with one click
Continue reading
Try Bird on your next bug - you’ll love it
“Game changer”
Julie, Head of QA
Try Bird later, from your desktop