Selenium remains one of the most widely used automation tools for testing, web scraping, and simulating user actions in modern browsers. As it was developed for application testing, it has no native proxy support, but integration is still possible.
What is Selenium?
Selenium is an open-source automation framework that people use to automate web browsers. It’s a great option for when you need to work with JavaScript-heavy websites or several different browsers. It’s usually slower than most other modern frameworks, but it gets the job done and there’s plenty of documentation.
Developers use it for tasks like:
- Automated UI testing across browsers and platforms.
- Repetitive web tasks like form submissions or data entry.
- Web scraping projects that require interaction with dynamic content.
- Simulating real user activity for performance and functionality testing.
If you’re experiencing CAPTCHA issues, you should check out our guide about bypassing CAPTCHA challenges in Selenium.
Why Use Proxies in Selenium?
Pairing Selenium with a proxy server provides a layer of privacy, data accessibility, and geo-targeting. Without a Selenium proxy, requests would come directly from your device and your IP address, which will quickly lead to rate limits or IP bans.
Here some some benefits that a proxy server offers:
- Anonymity. Hide your real IP address behind a proxy server.
- Geo-targeting. Access region-specific content by using IPs from different countries.
- Avoiding bans. Reduce the risk of blocks and bans during web scraping.
- Scalability. Use pools of rotating proxy servers for large projects.
Here’s how some Selenium proxies compare against each other:
Residential proxy
ISP proxy
Datacenter proxy
Mobile proxy
Harder to detect, genuine IPs
Offers better stability than residential IPs at a cost typically higher than datacenter and close to residential, depending on your usage
Very fast and cheap
Often considered most genuine
More expensive than datacenter proxies
More limited IP pools
Easy to detect and block
Costly and potentially slower
How to Integrate Proxies in Selenium With Python
Using a proxy in Selenium with Python is quite straightforward. Here is a step-by-step example using Chrome WebDriver.
1. Installing Dependencies
pip install selenium
2. Configuring Proxy Authentication
There are several options you can do: either proceed without authentication if possible, use Selenium Wire (which is the simplest way), or go with a Chrome extension.
Option 1: No Authentication
Use a basic proxy server that doesn’t require credentials:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
PROXY = "http://ip-address:port"
opts = Options()
opts.add_argument(f"--proxy-server={PROXY}")
driver = webdriver.Chrome(options=opts)
Option 2: Selenium Wire Authentication
Selenium-wire uses a library called setuptools that is no longer default with Python and an older version of blinker. Install all at once by running:
pip install selenium-wire setuptools "blinker<1.6"
from seleniumwire import webdriver
from selenium.webdriver.chrome.options import Options
proxy_host = "ip_address"
proxy_port = 8000
proxy_user = "username"
proxy_pass = "password"
opts = Options()
seleniumwire_options = {
"proxy": {
"http": f"http://{proxy_user}:{proxy_pass}@{proxy_host}:{proxy_port}",
"https": f"http://{proxy_user}:{proxy_pass}@{proxy_host}:{proxy_port}",
"no_proxy": "localhost,127.0.0.1"
}
}
driver = webdriver.Chrome(options=opts, seleniumwire_options=seleniumwire_options
Option 3: Chrome Extension Authentication
If you prefer not to add libraries, you can generate a tiny Chrome extension on the fly that applies your proxy configuration and supplies proxy credentials automatically:
import zipfile, os
from selenium import webdriver # selenium import webdriver
from selenium.webdriver.chrome.options import Options
proxy_host = "ip_address"
proxy_port = 8000
proxy_user = "username"
proxy_pass = "password"
manifest_json = """
{
"name": "Proxy Auth Extension",
"version": "1.0",
"manifest_version": 3,
"permissions": ["proxy", "storage", "webRequest", "webRequestBlocking"],
"host_permissions": ["<all_urls>"],
"background": { "service_worker": "background.js" }
}
"""
background_js = f"""
chrome.proxy.settings.set({{
value: {{
mode: "fixed_servers",
rules: {{
singleProxy: {{ scheme: "http", host: "{proxy_host}", port: {proxy_port} }},
bypassList: ["localhost"]
}}
}},
scope: "regular"
}}, function(){{}});
chrome.webRequest.onAuthRequired.addListener(
function(details) {{
return {{ authCredentials: {{ username: "{proxy_user}", password: "{proxy_pass}" }} }};
}},
{{urls: ["<all_urls>"]}},
["blocking"]
);
"""
plugin_path = "proxy_auth_plugin.zip"
with zipfile.ZipFile(plugin_path, "w") as zp:
zp.writestr("manifest.json", manifest_json)
zp.writestr("background.js", background_js)
opts = Options()
opts.add_extension(plugin_path)
# Also set the proxy for Chrome itself
opts.add_argument(f"--proxy-server=http://{proxy_host}:{proxy_port}") # proxy settings
driver = webdriver.Chrome(options=opts)
3. Launching Selenium With Proxy Options
If you followed any option above, your Selenium proxy is already active once you initiate the driver. For clarity, here’s a minimal end-to-end example (without authentication):
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
PROXY = "ip_address"
opts = Options()
opts.add_argument(f"--proxy-server={PROXY}") # proxy settings
driver = webdriver.Chrome(options=opts)
driver.get("https://httpbin.org/ip")
print(driver.page_source)
# driver.quit()
4. Verifying Proxy
Use a simple endpoint like https://httpbin.org/ip and confirm the response matches your proxy server IP and not your local IP:
import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
PROXY = "ip_address"
opts = Options()
opts.add_argument(f"--proxy-server={PROXY}")
driver = webdriver.Chrome(options=opts)
driver.get("https://httpbin.org/ip")
time.sleep(0.5) # give the page a moment to render text
body_text = driver.page_source
ip_str = body_text.split("{")[-1].split("}")[0]
print("IP response:", "{" + ip_str + "}")
# driver.quit()
If the printed IP equals the proxy address’s public IP, your Selenium proxy integration works. If you’re looking for more detailed information, check out our guide on web scraping with Selenium and Python.
How to Integrate Proxies in Selenium With Java
If you’re using Java, proxy integration in Selenium is handled slightly differently.
1. Installing Dependencies
Make sure you have the Selenium Java bindings in your project. If you use Maven, include this in your pom.xml:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.23.0</version>
</dependency>
2. Configuring a Basic Proxy (No Authentication)
import org.openqa.selenium.Proxy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
public class SeleniumProxyExample {
public static void main(String[] args) {
// Define proxy address
String proxyAddress = "ip_address";
// Create Proxy object
Proxy proxy = new Proxy();
proxy.setHttpProxy(proxyAddress)
.setSslProxy(proxyAddress);
// Attach proxy to Chrome options
ChromeOptions options = new ChromeOptions();
options.setProxy(proxy);
// Launch browser with proxy
WebDriver driver = new ChromeDriver(options);
driver.get("https://httpbin.org/ip");
System.out.println(driver.getPageSource());
driver.quit();
}
]
It confirms your Selenium proxy setup by showing the proxy server IP.
3. Configuring Proxy Authentication (With Username and Password)
Selenium Java doesn’t natively support passing proxy credentials. If your proxy server requires authentication, you need a workaround, like using a Chrome extension (see the example given for Python)
You can generate a custom Chrome extension that injects authentication automatically. The extension sets the configuration and fills in the login prompt with your credentials.
4. Verifying Proxy
After setting up the Selenium proxy, go to an IP-checking site and check your IP. If the page shows the proxy server’s IP instead of your own, the setup is successful.
How to Integrate Proxies in Selenium With JavaScript (Node.js)
Finally, here’s a setup you can use for Node.js using ChromeDriver.
1. Installing Dependencies
npm install selenium-webdriver adm-zip
If you also want Firefox support, use:
npm install geckodrive
2. Configuring Proxy Authentication
Same as with the other options, there are several methods where you can go with no authentication or extension-based authentication.
Option 1: No Authentication
const { Builder, By } = require('selenium-webdriver');
const chrome = require('selenium-webdriver/chrome');
(async () => {
const PROXY = 'ip_address';
const options = new chrome.Options()
.addArguments(`--proxy-server=${PROXY}`);
const driver = await new Builder()
.forBrowser('chrome')
.setChromeOptions(options)
.build();
try {
await driver.get('https://httpbin.org/ip');
const body = await driver.findElement(By.css('body')).getText();
console.log('IP response:', body);
} finally {
await driver.quit();
}
})();
Option 2: Chrome Extension Authentication
const { Builder, By } = require('selenium-webdriver');
const chrome = require('selenium-webdriver/chrome');
const AdmZip = require('adm-zip');
(async () => {
const proxyHost = "ip_address";
const proxyPort = 8000;
const proxyUser = 'username';
const proxyPass = 'password';
const manifest = `
{
"name": "Proxy Auth Extension",
"version": "1.0",
"manifest_version": 3,
"permissions": ["proxy", "storage", "webRequest", "webRequestBlocking"],
"host_permissions": ["<all_urls>"],
"background": { "service_worker": "background.js" }
}`;
const background = `
chrome.proxy.settings.set({
value: {
mode: "fixed_servers",
rules: {
singleProxy: { scheme: "http", host: "${proxyHost}", port: ${proxyPort} }
,
bypassList: ["localhost"]
}
},
scope: "regular"
}, function(){});
chrome.webRequest.onAuthRequired.addListener(
function() {
return { authCredentials: { username: "${proxyUser}", password: "${proxyPass}" } };
},
{ urls: ["<all_urls>"] },
["blocking"]
);`;
// Build the extension ZIP in-memory
const zip = new AdmZip();
zip.addFile('manifest.json', Buffer.from(manifest, 'utf8'));
zip.addFile('background.js', Buffer.from(background, 'utf8'));
const extensionBuffer = zip.toBuffer();
const options = new chrome.Options()
.addArguments(`--proxy-server=http://${proxyHost}:${proxyPort}`)
.addExtensions(extensionBuffer); // loads the auth extension
const driver = await new Builder()
.forBrowser('chrome')
.setChromeOptions(options)
.build();
try {
await driver.get('https://httpbin.org/ip');
const body = await driver.findElement(By.css('body')).getText();
console.log('IP response:', body);
} finally {
await driver.quit();
}
})();
3. Verifying the Proxy With an IP-Checking Site
Use a simple endpoint and confirm it returns the proxy’s public IP, not your local one:
// Reuse any of the drivers above after navigation:
await driver.get('https://httpbin.org/ip’);
const txt = await driver.findElement(By.css('body')).getText();
console.log('Effective public IP:', txt);
If you see the proxy’s public IP, your setup is correct.

