Selenium Proxy Setup
Selenium is the most established browser automation framework, supporting Chrome, Firefox, Edge, and Safari across Python, Java, C#, Ruby, and JavaScript. It is widely used for web scraping, automated testing, and QA workflows. Selenium supports proxy configuration through browser options, making it compatible with Hex Proxies for all supported browsers.
Why Use Proxies with Selenium?
Selenium scripts that run without proxies reveal your server IP to every target. Anti-bot platforms detect repeated automated access and block the IP. Residential proxies from Hex Proxies rotate your apparent IP address, reducing blocks and enabling geo-targeted browsing from 195+ countries.
Chrome Configuration with Proxy Auth
from selenium import webdriver# Method 1: Via Chrome options (simplest) options = webdriver.ChromeOptions() options.add_argument('--proxy-server=http://gate.hexproxies.com:8080')
driver = webdriver.Chrome(options=options) driver.get('https://httpbin.org/ip') print(driver.page_source) driver.quit() ```
Handling Proxy Authentication
Selenium does not natively support proxy username/password via the WebDriver API. Use one of these approaches:
**Option A: IP Whitelisting (recommended)** — Whitelist your server IP in the Hex Proxies dashboard. No credentials needed in code.
**Option B: Chrome Extension** — Create a lightweight Chrome extension that injects proxy auth headers:
manifest = { "version": "1.0.0", "manifest_version": 2, "name": "Proxy Auth", "permissions": ["proxy", "webRequest", "webRequestBlocking", "<all_urls>"], "background": {"scripts": ["background.js"]} } background = """ chrome.webRequest.onAuthRequired.addListener( function(details) { return {authCredentials: {username: "your-hex-username", password: "your-hex-password"}}; }, {urls: ["<all_urls>"]}, ["blocking"] );"""
with zipfile.ZipFile('proxy_auth.zip', 'w') as zp: zp.writestr("manifest.json", json.dumps(manifest)) zp.writestr("background.js", background)
options = webdriver.ChromeOptions() options.add_extension('proxy_auth.zip') options.add_argument('--proxy-server=http://gate.hexproxies.com:8080') ```
SOCKS5 Configuration
options = webdriver.ChromeOptions()
options.add_argument('--proxy-server=socks5://gate.hexproxies.com:1080')Best Practices
- Use **sticky sessions** for login flows and multi-step navigations.
- **Rotate IPs between test runs** to avoid accumulating blocks on a single address.
- Add **implicit or explicit waits** to handle the additional latency from proxy routing.
- Combine proxy rotation with **user-agent rotation** for stronger fingerprint diversity.
Troubleshooting
- **Proxy auth popup**: Use IP whitelisting or the Chrome extension method above. Selenium cannot dismiss native auth dialogs programmatically.
- **Timeouts**: Increase implicit wait times when using residential proxies. Set `driver.set_page_load_timeout(60)`.
- **SSL certificate errors**: Add `options.add_argument('--ignore-certificate-errors')` if you encounter proxy-related SSL warnings.
- **Blocks on protected sites**: Switch from datacenter to residential proxies and reduce request frequency.