Scraping and automation libraries

How to use a proxy with Selenium

Selenium WebDriver automates real Chrome, Firefox and Edge browsers and is common in testing teams and older scraping stacks. Setting a proxy address is easy, but WebDriver has no standard way to send a proxy username and password, which is where most Selenium proxy problems start.

There are two reliable approaches. selenium-wire runs a small local proxy that adds your credentials, so the browser itself needs none. The second is to allowlist your server IP in the dashboard and pass only the gateway address with --proxy-server.

Updated 23 November 2026

What you need
Hostgate.firstproxy.shop
HTTP / HTTPS port8000
SOCKS5 port9000
Usernameuser-country-us
PasswordYOUR_TOKEN

With selenium-wire you can use HTTP on 8000 or SOCKS5 on 9000 with credentials. With plain --proxy-server, credentials are not possible, so use the allowlist. Your username and token appear on the Proxy setup page of your dashboard after your first order.

Setup

How do I connect Selenium to a proxy?

Follow the steps in order. Replace YOUR_TOKEN with the token from your dashboard and change the country, city or session in the username to suit the job.

  1. Install Selenium and selenium-wire

    Selenium 4.6 and later downloads the right driver automatically through Selenium Manager. selenium-wire is no longer actively maintained and imports a module removed in blinker 1.8, so pin blinker to 1.7.0 alongside it.

    python -m pip install selenium selenium-wire "blinker==1.7.0"
  2. Why --proxy-server alone fails

    Chrome reads --proxy-server as an address only. Writing user:pass@ inside it is ignored, and the browser then shows a sign-in dialog that WebDriver cannot fill. Firefox proxy preferences have the same limit. That is why the next steps add credentials outside the browser.

  3. Connect with username and password through selenium-wire

    Import webdriver from seleniumwire instead of selenium and pass the proxy in seleniumwire_options. The no_proxy list keeps the local driver traffic direct.

    from seleniumwire import webdriver
    
    PROXY = "http://user-country-us:YOUR_TOKEN@gate.firstproxy.shop:8000"
    options = {
        "proxy": {
            "http": PROXY,
            "https": PROXY,
            "no_proxy": "localhost,127.0.0.1",
        }
    }
    
    driver = webdriver.Chrome(seleniumwire_options=options)
    driver.get("https://ipinfo.io/json")
    print(driver.find_element("tag name", "body").text)
    driver.quit()
  4. Keep one IP for a test run

    Build the username with a session per driver. Tests that log in and click through several pages then stay on one IP, and parallel workers each get their own.

    import uuid
    
    sid = uuid.uuid4().hex[:8]
    user = f"user-country-us-city-chicago-session-{sid}-ttl-30m"
    PROXY = f"http://{user}:YOUR_TOKEN@gate.firstproxy.shop:8000"
    
    driver = webdriver.Chrome(seleniumwire_options={
        "proxy": {"http": PROXY, "https": PROXY, "no_proxy": "localhost,127.0.0.1"}
    })
  5. Use plain Selenium with an IP allowlist

    If you would rather not run selenium-wire, add the public IPv4 address of the machine running the tests to the allowlist in your dashboard (up to 10 addresses). Requests from that address are accepted without a password, so --proxy-server with only the host and port works. This suits stable servers and CI runners with a fixed IP.

    from selenium import webdriver
    
    opts = webdriver.ChromeOptions()
    opts.add_argument("--proxy-server=http://gate.firstproxy.shop:8000")
    driver = webdriver.Chrome(options=opts)
    driver.get("https://ipinfo.io/json")

    Without a username, there is nowhere to write country or session targeting. Use selenium-wire when each run needs its own location or sticky session.

Test

How do I check that the proxy works?

Load ipinfo.io/json in the driven browser and print the page text. Compare it with a run without the proxy to be sure the IP changed.

A working proxy returns a response like the one shown, trimmed to the main fields. The IP belongs to the exit, the city and country follow your username, and the time zone is where that IP is located, here United States.

driver.get("https://ipinfo.io/json")
print(driver.find_element("tag name", "body").text)
ipinfo.io/json response
{
  "ip": "203.0.113.24",
  "city": "New York",
  "country": "US",
  "timezone": "America/New_York"
}

203.0.113.24 is a documentation address. Your result shows a real exit IP.

Targeting

How do I set country, city and session in the username?

All targeting is written into the username, so Selenium needs no extra settings to change location. Parts are joined with hyphens in this order after your proxy user. The password is always your token.

Proxy username parts
PartFormatExampleRule
Country-country-{cc}-country-usRequired. Two-letter country code in lowercase. 64 countries are available.
City-city-{city}-city-new-yorkOptional. City name in lowercase, spaces become hyphens. 172 cities are available.
Session-session-{id}-session-a1b2c3Optional. Any letters and digits you choose. The same id keeps the same IP, a new id gets a new IP.
Session length-ttl-{minutes}m-ttl-30mUsed with a session. Residential 1 to 120 minutes, mobile 1 to 60, long-acting ISP up to 720 (12 hours).
Full usernameuser-country-us-city-new-york-session-a1b2c3-ttl-30m

Find country codes and city values on the proxy locations page.

Troubleshooting

Selenium proxy errors and fixes

The problems people run into most often with Selenium, with the message you are likely to see and how to solve it.

ImportError: cannot import name _saferef from blinker

blinker 1.8 removed a module that selenium-wire still uses. Install blinker==1.7.0 in the same environment.

A proxy sign-in dialog blocks the test

Credentials were put into --proxy-server or Firefox preferences, where they are ignored. Switch to selenium-wire, or allowlist the machine IP and drop the credentials.

Certificate warnings with selenium-wire

selenium-wire decrypts HTTPS locally to add headers, using its own certificate authority. It tells the driver to accept that certificate. If a site or test rejects it, use allowlist mode, which leaves TLS untouched.

407 even though the allowlist is set

The allowlist checks the public IP the request comes from. Behind NAT, a VPN or a cloud runner, that differs from the local address. Look up your public IP and add that one.

Pages slow down under selenium-wire

Every request passes through Python. Set driver.scopes to the domains you need to inspect, or disable request capture with the disable_capture option, to cut the overhead.

FAQ

Selenium proxy questions

Short answers to what people ask most about using a proxy with Selenium.

How do I use a proxy with username and password in Selenium?

Use selenium-wire and pass the proxy URL with credentials in seleniumwire_options. Plain Selenium cannot send proxy credentials, because Chrome and Firefox read only a host and port from their proxy settings.

Can I put user:pass in --proxy-server for Chrome?

No. Chrome ignores credentials in that flag and shows a sign-in dialog instead. Use selenium-wire or allowlist the IP of the machine that runs the browser.

Is selenium-wire still safe to use?

It works with Selenium 4 but is no longer actively maintained. Pin blinker to 1.7.0 and test after Selenium upgrades. For long-term projects, allowlist mode or a move to Playwright avoids the dependency.

How do I rotate the IP between Selenium tests?

Start each driver with a new session name in the username, or with no session for rotating IPs. Allowlist mode uses one gateway address, so per-test targeting needs selenium-wire.

Get your token and run the first Selenium request

Create an account, top up from $40 with crypto, and copy the gateway, username and token from the dashboard.