# Using proxies with Selenium WebDriver (Chrome and Firefox)

The classic Selenium problem is authentication: browsers show a credentials prompt WebDriver cannot fill. Two clean answers: whitelist your server, or let Selenium Wire inject the credentials.


## Option 1: IP whitelisting (recommended for servers)

Add your server's public IPv4 to the [whitelist](https://proxshift.com/docs/authentication) in the dashboard. Chrome then needs only the proxy address and never shows a prompt. The limit: a browser that is not challenged sends no username, so the gateway cannot read targeting parameters and uses the account's default pool. When each session needs its own country or sticky id, use Option 2.

```python
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

opts = Options()
opts.add_argument("--proxy-server=http://res.proxshift.com:9000")
opts.add_argument("--headless=new")
driver = webdriver.Chrome(options=opts)
driver.get("https://api.ipify.org")
print(driver.find_element("tag name", "body").text)
driver.quit()
```


## Option 2: Selenium Wire (username, password and parameters)

Selenium Wire runs a local proxy that adds the credentials for you, so the ProxShift URL with all its parameters works unchanged.

```python
from seleniumwire import webdriver
from selenium.webdriver.chrome.options import Options

proxy = "http://USER-cc-de-city-berlin-sid-sel1-ttl-30m:PASS@res.proxshift.com:9000"
sw_options = {"proxy": {"http": proxy, "https": proxy, "no_proxy": "localhost,127.0.0.1"}}

opts = Options()
opts.add_argument("--headless=new")
driver = webdriver.Chrome(seleniumwire_options=sw_options, options=opts)
driver.get("https://api.ipify.org")
print(driver.find_element("tag name", "body").text)
driver.quit()
```

> Warn: Selenium Wire intercepts TLS locally to add headers; it installs its own certificate in the browser it drives. Fine for automation, not for anything where certificate integrity matters.


## Firefox

```python
from selenium import webdriver
from selenium.webdriver.firefox.options import Options

opts = Options()
opts.set_preference("network.proxy.type", 1)
opts.set_preference("network.proxy.http", "res.proxshift.com")
opts.set_preference("network.proxy.http_port", 9000)
opts.set_preference("network.proxy.ssl", "res.proxshift.com")
opts.set_preference("network.proxy.ssl_port", 9000)
opts.set_preference("media.peerconnection.enabled", False)  # no WebRTC leak
driver = webdriver.Firefox(options=opts)  # whitelisted server, no prompt
```


## Practical rules

- One driver per session id; drivers keep connections alive, so the exit stays the same until the session lifetime ends.
- Use `--headless=new` in Chrome; the old headless mode has a distinctive fingerprint.
- Set the browser language and time zone to the exit's country; Selenium Wire can also rewrite `Accept-Language`.


## Questions

**Why does Chrome show a proxy login prompt with Selenium?**

WebDriver has no API to answer the proxy authentication dialog. Whitelist your IP so no prompt appears, or run Selenium Wire, which injects the Proxy-Authorization header for you.

Source: https://proxshift.com/guides/selenium-proxy
