Selenium WebDriver is one of the most popular tools for browser automation and data scraping. When dealing with large volumes of requests or the need to bypass geographical restrictions, it is critically important to configure proxies correctly. In this guide, we will explore all the ways to integrate proxies into Selenium for different browsers and programming languages, as well as address common issues faced by developers.
Why Use Proxies in Selenium
When automating web scraping or testing through Selenium, several tasks arise that cannot be solved without proxies:
- Bypassing Rate Limiting β many websites limit the number of requests from a single IP address. Without proxies, your script will quickly get blocked after 50-100 requests.
- Geographical Restrictions β if you need to scrape content available only from a specific country, a proxy with the required geolocation IP solves this problem.
- Load Distribution β during mass data scraping, rotating IP addresses through proxies allows you to distribute requests and avoid bot detection.
- Localization Testing β to check how a website appears to users from different countries, proxies from the corresponding regions are necessary.
- Bypassing Anti-Bot Systems β modern protections (Cloudflare, DataDome) analyze IP reputation. Quality proxies help you appear as a regular user.
Without proper proxy configuration, your Selenium script will operate unstably: encountering CAPTCHAs, temporary bans, or complete access blocks. This is especially critical when scraping e-commerce platforms, social networks, or sites with aggressive bot protection.
What Types of Proxies to Use
The choice of proxy type depends on the task. For Selenium automation, there are three main types of proxies, each with its advantages:
| Proxy Type | Speed | Anonymity | Best Use Cases |
|---|---|---|---|
| Data Center Proxies | Very High (100+ Mbps) | Medium | Scraping public data, performance testing, bulk checks |
| Residential Proxies | Medium (10-50 Mbps) | Very High | Bypassing anti-bot systems, scraping social networks, e-commerce, sites with strict protection |
| Mobile Proxies | Medium (5-30 Mbps) | Maximum | Working with mobile versions of sites, social networks, applications with mobile IP verification |
Selection Recommendations:
- For scraping news sites, open APIs, simple directories β data center proxies will suffice. They are cheaper and faster.
- For working with Amazon, eBay, Google, social networks β only residential proxies. These platforms actively block data center IPs.
- For emulating mobile users or working with Instagram, TikTok β mobile proxies are indispensable.
- For geolocation testing β choose proxies that allow you to select a specific country and city.
Setting Up a Proxy for Chrome in Selenium
Chrome WebDriver is the most popular choice for Selenium automation. Proxy configuration is done through the ChromeOptions object. Letβs look at several methods.
Method 1: HTTP/HTTPS Proxy Without Authentication (Python)
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
# Proxy configuration
PROXY = "123.45.67.89:8080" # Replace with your proxy server
chrome_options = Options()
chrome_options.add_argument(f'--proxy-server=http://{PROXY}')
# Additional options for stability
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
# Launching the driver
driver = webdriver.Chrome(options=chrome_options)
# Checking IP
driver.get('https://httpbin.org/ip')
print(driver.page_source)
driver.quit()
Method 2: SOCKS5 Proxy (Python)
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
PROXY = "123.45.67.89:1080"
chrome_options = Options()
# For SOCKS5, specify the protocol explicitly
chrome_options.add_argument(f'--proxy-server=socks5://{PROXY}')
driver = webdriver.Chrome(options=chrome_options)
driver.get('https://httpbin.org/ip')
print(driver.page_source)
driver.quit()
Important: Chrome supports HTTP, HTTPS, and SOCKS5 proxies. SOCKS4 requires additional configurations or the use of extensions.
Setting Up a Proxy for Chrome in Java
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.Proxy;
public class ChromeProxyExample {
public static void main(String[] args) {
// Proxy configuration
Proxy proxy = new Proxy();
proxy.setHttpProxy("123.45.67.89:8080");
proxy.setSslProxy("123.45.67.89:8080");
ChromeOptions options = new ChromeOptions();
options.setProxy(proxy);
options.addArguments("--no-sandbox");
WebDriver driver = new ChromeDriver(options);
driver.get("https://httpbin.org/ip");
System.out.println(driver.getPageSource());
driver.quit();
}
}
Setting Up a Proxy for Firefox in Selenium
Firefox WebDriver uses a different approach to proxy configuration through the browser profile. This provides more flexibility but requires an understanding of configuration parameters.
HTTP/HTTPS Proxy for Firefox (Python)
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
PROXY_HOST = "123.45.67.89"
PROXY_PORT = 8080
firefox_options = Options()
# Proxy configuration through preferences
firefox_options.set_preference("network.proxy.type", 1)
firefox_options.set_preference("network.proxy.http", PROXY_HOST)
firefox_options.set_preference("network.proxy.http_port", PROXY_PORT)
firefox_options.set_preference("network.proxy.ssl", PROXY_HOST)
firefox_options.set_preference("network.proxy.ssl_port", PROXY_PORT)
# Disable proxy for local addresses
firefox_options.set_preference("network.proxy.no_proxies_on", "localhost,127.0.0.1")
driver = webdriver.Firefox(options=firefox_options)
driver.get('https://httpbin.org/ip')
print(driver.page_source)
driver.quit()
SOCKS5 Proxy for Firefox (Python)
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
PROXY_HOST = "123.45.67.89"
PROXY_PORT = 1080
firefox_options = Options()
firefox_options.set_preference("network.proxy.type", 1)
firefox_options.set_preference("network.proxy.socks", PROXY_HOST)
firefox_options.set_preference("network.proxy.socks_port", PROXY_PORT)
firefox_options.set_preference("network.proxy.socks_version", 5)
# For SOCKS5 with DNS through proxy
firefox_options.set_preference("network.proxy.socks_remote_dns", True)
driver = webdriver.Firefox(options=firefox_options)
driver.get('https://httpbin.org/ip')
print(driver.page_source)
driver.quit()
Advantage of Firefox: The network.proxy.socks_remote_dns parameter allows DNS requests to be made through the proxy, enhancing anonymity and helping to bypass DNS-level blocks.
Working with Proxies Requiring Authentication
Most quality proxy services use authentication via username and password. Selenium does not support passing credentials directly in the proxy URL for Chrome, so workarounds are required.
Method 1: Chrome Extension for Authentication (Recommended)
We create a temporary Chrome extension that automatically fills in the username and password when connecting to the proxy:
import os
import zipfile
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
PROXY_HOST = "123.45.67.89"
PROXY_PORT = 8080
PROXY_USER = "username"
PROXY_PASS = "password"
# Creating the extension manifest
manifest_json = """
{
"version": "1.0.0",
"manifest_version": 2,
"name": "Chrome Proxy",
"permissions": [
"proxy",
"tabs",
"unlimitedStorage",
"storage",
"webRequest",
"webRequestBlocking"
],
"background": {
"scripts": ["background.js"]
}
}
"""
# Script for authentication
background_js = """
var config = {
mode: "fixed_servers",
rules: {
singleProxy: {
scheme: "http",
host: "%s",
port: parseInt(%s)
},
bypassList: ["localhost"]
}
};
chrome.proxy.settings.set({value: config, scope: "regular"}, function() {});
function callbackFn(details) {
return {
authCredentials: {
username: "%s",
password: "%s"
}
};
}
chrome.webRequest.onAuthRequired.addListener(
callbackFn,
{urls: [""]},
['blocking']
);
""" % (PROXY_HOST, PROXY_PORT, PROXY_USER, PROXY_PASS)
# Creating the extension
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)
# Launching Chrome with the extension
chrome_options = Options()
chrome_options.add_extension(plugin_path)
driver = webdriver.Chrome(options=chrome_options)
driver.get('https://httpbin.org/ip')
print(driver.page_source)
driver.quit()
os.remove(plugin_path) # Deleting the temporary file
Method 2: Firefox with Authentication (Easier)
Firefox allows credentials to be passed through profile settings:
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
PROXY_HOST = "123.45.67.89"
PROXY_PORT = 8080
PROXY_USER = "username"
PROXY_PASS = "password"
firefox_options = Options()
firefox_options.set_preference("network.proxy.type", 1)
firefox_options.set_preference("network.proxy.http", PROXY_HOST)
firefox_options.set_preference("network.proxy.http_port", PROXY_PORT)
firefox_options.set_preference("network.proxy.ssl", PROXY_HOST)
firefox_options.set_preference("network.proxy.ssl_port", PROXY_PORT)
# Authentication (may not always work, depends on Firefox version)
firefox_options.set_preference("network.proxy.username", PROXY_USER)
firefox_options.set_preference("network.proxy.password", PROXY_PASS)
# Disabling the authentication prompt
firefox_options.set_preference("network.automatic-ntlm-auth.trusted-uris", PROXY_HOST)
driver = webdriver.Firefox(options=firefox_options)
driver.get('https://httpbin.org/ip')
print(driver.page_source)
driver.quit()
Note: If your proxy provider supports IP whitelisting, it is easier to add your server's IP to the whitelist and use the proxy without authentication.
Proxy Rotation in Selenium
When scraping large volumes of data, it is critically important to change proxies to avoid blocks. There are two approaches: code-level rotation and using rotating proxies.
Code-Level Rotation (Creating a New Driver)
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import random
# List of proxies
PROXY_LIST = [
"123.45.67.89:8080",
"98.76.54.32:8080",
"11.22.33.44:8080",
]
def create_driver_with_proxy(proxy):
"""Create a driver with the specified proxy"""
chrome_options = Options()
chrome_options.add_argument(f'--proxy-server=http://{proxy}')
chrome_options.add_argument('--no-sandbox')
return webdriver.Chrome(options=chrome_options)
# Scraping with rotation
urls_to_parse = [
'https://example.com/page1',
'https://example.com/page2',
'https://example.com/page3',
]
for url in urls_to_parse:
# Choose a random proxy
current_proxy = random.choice(PROXY_LIST)
# Create a new driver with the proxy
driver = create_driver_with_proxy(current_proxy)
try:
driver.get(url)
# Your scraping logic
print(f"Parsed {url} via {current_proxy}")
print(driver.title)
except Exception as e:
print(f"Error with {current_proxy}: {e}")
finally:
driver.quit() # Important to close the driver
Using Rotating Proxies (Easier)
Many proxy providers offer a rotating endpoint β a single URL that automatically changes IP with each request or at specific intervals. This simplifies the code:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
# Rotating proxy endpoint (IP changes automatically)
ROTATING_PROXY = "rotating.proxycove.com:8080"
chrome_options = Options()
chrome_options.add_argument(f'--proxy-server=http://{ROTATING_PROXY}')
driver = webdriver.Chrome(options=chrome_options)
# Each request will be from a new IP
urls = ['https://httpbin.org/ip'] * 5
for url in urls:
driver.get(url)
print(driver.find_element("tag name", "body").text)
# Each output will show a different IP
driver.quit()
Recommendation: For large projects, use rotating proxies β this saves resources (no need to recreate the driver) and simplifies the code. Residential proxies usually support rotation out of the box.
Common Errors and Their Solutions
Error: "ERR_PROXY_CONNECTION_FAILED"
Reason: Selenium cannot connect to the proxy server.
Solution:
- Check the correctness of the proxy IP and port
- Ensure that the proxy is active (check via curl:
curl -x http://123.45.67.89:8080 https://httpbin.org/ip) - Check the firewall β outgoing connections to the proxy may be blocked
- If using authentication, check the correctness of the username/password
Error: "ERR_TUNNEL_CONNECTION_FAILED"
Reason: Issue with HTTPS connection through the proxy.
Solution:
- Ensure that the proxy supports HTTPS (CONNECT method)
- For HTTPS sites, use HTTPS proxies or SOCKS5
- Add an option to ignore SSL errors:
chrome_options.add_argument('--ignore-certificate-errors')
Error: Proxy Works, but Site Detects Bot
Reason: The site uses advanced detection methods (fingerprinting, behavior analysis).
Solution:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument(f'--proxy-server=http://{PROXY}')
# Disabling the webdriver flag (main indicator of automation)
chrome_options.add_experimental_option("excludeSwitches", ["enable-automation"])
chrome_options.add_experimental_option('useAutomationExtension', False)
driver = webdriver.Chrome(options=chrome_options)
# Removing navigator.webdriver
driver.execute_cdp_cmd('Page.addScriptToEvaluateOnNewDocument', {
'source': '''
Object.defineProperty(navigator, 'webdriver', {
get: () => undefined
})
'''
})
driver.get('https://bot.sannysoft.com/') # Site for detection testing
Additionally, it is recommended to use the undetected-chromedriver library, which automatically applies many anti-detection techniques.
Problem: Slow Page Loads Through Proxy
Reason: The proxy is overloaded or located geographically far away.
Solution:
- Choose proxies closer to the target server (for example, use US proxies for scraping US sites)
- Use data center proxies for tasks where speed is more important than anonymity
- Set timeouts in Selenium to avoid hangs:
from selenium.webdriver.support.ui import WebDriverWait
driver.set_page_load_timeout(30) # Maximum 30 seconds to load
driver.implicitly_wait(10) # Implicit wait for elements
Best Practices When Working with Proxies
1. Use Proxy Pools
Do not rely on a single proxy server. Create a pool of 10-50 proxies and rotate them. If one proxy gets banned, scraping will continue with another.
2. Add Random Delays
Even with proxies, requests that are too fast look suspicious. Add random delays of 2-5 seconds between requests:
import time
import random
for url in urls:
driver.get(url)
# Scraping...
time.sleep(random.uniform(2, 5)) # Random delay of 2-5 seconds
3. Monitor Proxy Quality
Check proxies before use. Exclude from the pool those that do not respond or return errors:
import requests
def check_proxy(proxy):
"""Check the functionality of the proxy"""
try:
response = requests.get(
'https://httpbin.org/ip',
proxies={'http': f'http://{proxy}', 'https': f'http://{proxy}'},
timeout=10
)
return response.status_code == 200
except:
return False
# Filtering working proxies
working_proxies = [p for p in PROXY_LIST if check_proxy(p)]
print(f"Working proxies: {len(working_proxies)}/{len(PROXY_LIST)}")
4. Use Headless Mode with Caution
Headless browsers are easier to detect. For complex sites, run the browser in normal mode or use --window-size instead of --headless.
5. Log All Requests
Keep track of which proxy was used for each request. This will help identify problematic proxies and debug errors.
6. Respect robots.txt and Rate Limits
Even with proxies, respect the site's rules. Aggressive scraping can lead to the blocking of entire proxy subnets, which can harm other users.
Conclusion
Properly configuring proxies in Selenium WebDriver is the foundation of stable scraping and automation. We have covered all the main ways to integrate proxies for Chrome and Firefox, working with authentication, IP rotation, and solving common problems. The key is to choose the right type of proxy for your task: for simple scraping, data center proxies are sufficient, while for working with protected platforms, residential or mobile proxies are necessary.
Remember the best practices: use proxy pools, add random delays, monitor connection quality, and apply anti-detection techniques. This will increase the stability of your scripts and reduce the risk of blocks by dozens of times.
If you plan to automate scraping with high anonymity and anti-bot system bypass requirements, we recommend trying residential proxies β they provide maximum stability when working with any sites, including social networks, e-commerce platforms, and services with advanced protection. For tasks where speed in processing large volumes of data is critical, data center proxies will be the optimal choice in terms of price-performance ratio.