How to set up a proxy in Selenium in Python

Comments: 0

Content of the article:

Selenium in Python is a vital tool for browser automation, offering a robust set of tools and libraries. It enables the development of automated tests that replicate user actions in web browsers. Its main components include:

  • WebDriver - an API for browser interaction, compatible with Chrome, Firefox, and other browsers.
  • IDE - a tool for recording and replaying browser actions.
  • Grid - facilitates browser testing across different operating systems and browsers simultaneously.

In addition to these, Selenium supports various tasks like error detection, web application quality assurance, news parsing, price monitoring, and automated website interactions such as registrations, form submissions, and button clicks.

Setting up a proxy for use in Selenium

To effectively use Selenium in Python for browser automation, start by installing the necessary library and choosing the appropriate WebDriver for your browser. For enhanced data protection during web scraping and to circumvent regional restrictions, configuring a proxy with Selenium is advisable.

Here's a step-by-step guide for setting up a proxy in Selenium, particularly for Google Chrome using WebDriver:

  1. Open your PC's runtime or terminal. Install WebDriver for Selenium with the commands shown in the accompanying screenshot.


  2. Initiate a new WebDriver instance for Google Chrome. Then, set up a proxy with an initial empty value, as demonstrated in the provided code snippet.


  3. For network debugging, configure the proxy server's address and port. Replace the placeholder “your_proxy_server:your_port” with the actual proxy server details, using a colon as a separator.


  4. For proxy authentication in Selenium, input the code from the screenshot, substituting 'SOCKS' with the necessary protocol.


  5. To activate these settings in WebDriver and launch the browser with your configurations, input the corresponding code in the terminal. While this guide focuses on Chrome, you can adapt it for other browsers, like Firefox, by replacing “webdriver.DesiredCapabilities.CHROME” with the relevant browser code.


  6. Finally, input the target website address into the driver settings, replacing “” with your desired site, such as “” or “”. Conclude by closing the browser using the “driver.quit” command.


Following these steps will streamline network settings management in Selenium, enhance online privacy, and make automated web interactions more discreet.