$0.00
A

Proxyvizr blog

How to set up a proxy in Selenium

In Selenium with Chrome the proxy is set with a launch flag. The tricky part is authentication: Chrome does not accept a username and password in the proxy address. Here is how to work around it.

Where to get the proxy details

Buy proxies in the Proxyvizr catalog or unified search and open "My proxies". Each proxy has a host:port:username:password line there, and traffic packages generate a list for the country you need on the same page. If your software needs another format, convert the list with the free Proxyvizr proxy converter.

Proxy without a password

If the provider supports IP authentication, it is simple: whitelist your IP and pass the proxy address:

from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument("--proxy-server=http://HOST:PORT")
driver = webdriver.Chrome(options=options)
driver.get("https://proxyvizr.com/api/my-ip")
print(driver.find_element("tag name", "body").text)
driver.quit()

Proxy with username and password

Chrome ignores credentials in --proxy-server and shows a login prompt that Selenium cannot fill in. Working options:

1. IP authentication at the provider, if offered. 2. A Chrome extension that supplies the username and password when the proxy asks for authentication. 3. A local forwarding proxy on your machine: Selenium connects to it without a password, and it connects to your proxy with the password. 4. Switch to Playwright or Puppeteer, which have proxy authentication built in.

The selenium-wire library used to solve this, but it is no longer maintained, so it is not the best choice for new projects.

SOCKS5

The --proxy-server=socks5://HOST:PORT flag works only without a password, the same limitation as regular Chrome.

Common mistakes

Credentials in the proxy address: Chrome will not accept them. One proxy for all drivers when working with several accounts. Not checking the IP before work.

Conclusion

In Selenium the proxy address is a Chrome flag, and password authentication needs a workaround. IP authentication or moving to Playwright is the simplest.

Ready to pick your proxies?

Create an account in a minute and choose proxies for your task — residential, mobile, ISP, datacenter and SOCKS5 from trusted providers.