Master Proxy Setup in Selenium

Related Product On This Page What is Selenium Proxy?January 13, 2026 · 11 min read · Tool Comparison

Related Product

How to set Proxy in Selenium in 2026?

A proxy in Seleniumdeed as a middleman between yourbrowser and the internet, let you tocontroland monitorweb traffic. Proxies are mainlyused to ensure privacy and encapsulationbetween numerous interactional systems.

It can be used for a variety of purposes, such as simulating different geographic position, hiding your IP speech, or even intercepting and modifying requests and answer.

Overview

Setting up a proxy in Selenium allows testers to control web traffic, bypass limitation, and enhance security during mechanisation testing.

Setting Unauthenticated Proxy in Selenium

  • Load Selenium WebDriver
  • Define Proxy (IP: PORT)
  • Set ChromeOptions ()
  • Add proxy to options
  • Add the pick to the Chrome ()

Setting Authenticated Proxy in Selenium

  • Create a Chrome propagation
  • Add Extension to Selenium using add_extension to Selenium
  • Run the script to configure the procurator in Chrome using Selenium WebDriver
  • Test on real devices employ BrowserStack ’ s cloud Selenium grid for accuracy

In the following subdivision, I ’ ll explicate how to set up both unauthenticated and documented proxies in Selenium, ensuring you can well integrate them into your trial environment.

What is Selenium Proxy?

A Selenium proxy works as a middle level between automated browser sessions and the web.

It enables traffic routing, IP masking, entree to region-restricted content, and inspection of mesh action. It plays an crucial use in scenario such as,, and.

Proxies in Selenium are commonly utilize for:

  • Bypassing geo-restrictions:Perform by model access from different region.
  • Capturing and analyzing meshing traffic:Debugging requests, responses, and execution issues.
  • Enhancing security and privateness:Hiding the real IP address to avoid detection or blocking.
  • : Simulating slow or unstable connections to check website resiliency.

Selenium render built-in support for proxies through the Proxy family, which can be configure for browsers like Chrome, Firefox, and Edge. By integrating proxies into trial scripts, QA teams can ensure more racy and naturalistic examination scenario.

Selenium Proxy tests failing across browsers?

BrowserStack eliminates local network limits by running Selenium Proxy tests on real browsers and device at scale.

Authenticating Proxy in Selenium

Proxy servers are most helpful in executing localization tests. Let ’ s say a tester wants to open an E-commerce website and check that the proper language background and up-to-dateness appear for users from a specific country.

  • An easy way to verify this is to access the website as a user would from a target location.
  • Like most tests, it would be leisurely to automate this activity, especially when a website has to be check from multiple locations.

is the most widely ill-used tool for pass tests. Essentially, developers can use Selenium to monitor browser and website behavior without gap and executing an intact browser instance. This article will detail how to set up a proxy server and use it to access the website via Selenium.

Also Read:

1. Setting Up Unauthenticated Proxy

An unauthenticated proxy server in Selenium can be set up with the following steps:

  • Import from the package
  • Define the placeholder server (IP: PORT)
  • Set ChromeOptions ()
  • Add the proxy waiter statement to the pick
  • Add the options to the Chrome () instance
from selenium import webdriver PROXY = `` 11.456.448.110:8080 '' chrome_options = WebDriver.ChromeOptions () chrome_options.add_argument (' -- proxy-server= % s ' % PROXY) chrome = webdriver.Chrome (chrome_options=chrome_options) chrome.get (`` https: //www.google.com '')

Use this Chrome WebDriver instance to execute test that incorporate the proxy server. For model, the undermentioned code snippet tests to ensure that a search field shows the user ’ s current city as the default position.

def testUserLocationZurich (self): self.chrome.get (self.url) search = self.chrome.find_element_by_id ('user-city ') self.assertIn ('Zurich ', search.text)

To by create this code reusable across freestanding tests, define a method that take the proxy IP address as an argument.

selenium.webdriver.common.proxy & # 8211;Proxy contains info about the proxy character and necessary procurator scene.

Testers can run tests using an unauthenticated server. However, if they wish to use an authenticated server, they can follow the procedure below.

2. Setting Up an Authenticated Proxy in Selenium (JavaScript)

Authenticated proxy servers can be irksome to use in automated test as there ’ s no built-in way to pass along proxy server credentials in Selenium. As of now, there are two options to handle attested proxies. The correct choice depends on the testers ’ requirements. It depends on ingredient like the version of Selenium and the headless browser used in tests.

Let ’ s learn how to use it.

  • The good way to integrate authenticated proxies with Selenium is by usingPhantomJSas a instead of the Chrome WebDriver.
  • However, adding a browser extension to authenticate Selenium is potential.
  • While this approach is more complex, it can be used with the latest version of Selenium, which may be a requirement for some development teams.

Note: The following step useJavaScript. For a Python-based approach, name to this guide on

The initiatory step is create a by including two files in an archive call proxy.zip:

Background.js

var config = {mode: `` fixed_servers '', rules: {singleProxy: {scheme: `` http '', host: `` YOUR_PROXY_ADDRESS '', port: parseInt (PROXY_PORT)}, bypassList: [`` foobar.com '']}}; chrome.proxy.settings.set ({value: config, scope: `` regular ''}, function () {}); function callbackFn (details) {revert {authCredentials: {username: `` PROXY_USERNAME '', password: `` PROXY_PASSWORD ''}};} chrome.webRequest.onAuthRequired.addListener (callbackFn, {urls: [`` & lt; all_urls & gt; '']}, ['blocking ']);

manifest.js

{'' version '': `` 1.0.0 '', '' manifest_version '': 3, '' name '': `` Chrome Proxy '', '' permissions '': ['' Proxy '', '' Tabs '', '' unlimitedStorage '', '' Storage '', '' & lt; all_urls & gt; '', '' webRequest '', '' webRequestBlocking ''], '' background '': {'' handwriting '': [`` background.js '']}, '' Minimum_chrome_version '': '' 76.0.0 ''}

The Chrome extension can be added to Selenium utilise theadd_extension method:

from selenium importation webdriver from selenium.webdriver.chrome.options import Options chrome_options = Options () chrome_options.add_extension (`` proxy.zip '') driver = webdriver.Chrome (executable_path='chromedriver.exe ', chrome_options=chrome_options) driver.get (`` http: //google.com '') driver.close ()

This illustration uses a single proxy host in the extension. To add more proxy servers, the tester must make further modifications to thechrome.proxy API. If the quizzer uses a CI/CD host, they would feature to be sure that the build machine has Chrome installed and the relevant browser extension added.

Try running the code detailed above to set the proxy for Chrome using. Remember that Selenium tests must be run on a existent twist cloud to get accurate answer.

For autonomous testing across multiple user personas, check out SUSATest — it explores your app like 10 different real users.

BrowserStack ’ s of 3500+ real browsers and devices allows testers to automate visual UI tryout in. Sign up, select a device-browser-OS combination, and run costless tests.

Read More:

3. Setting Up an Authenticated Proxy in Selenium (Using Python)

Authenticated proxy servers introduce special complexity in Selenium mechanization because Selenium does not provide a native way to surpass proxy certification. In Python-based Selenium trial, handling authenticated placeholder typically requires external tooling or browser-level workarounds. The suitable approach depends on factors such as the Selenium variation, browser choice, and whether tests run in or CI environments.

Below are the commonly utilise and practical approaches for Python users.

Option 1: Using Selenium Wire (Recommended for Python)

Selenium Wire is a Python library that extends Selenium WebDriver and provides built-in support for authenticated proxies without requiring browser extensions. It intercepts HTTP/HTTPS traffic and let credential to be configured directly in code.

This approach is easy to maintain and works well with modern version of Selenium and Chrome.

Example:

from seleniumwire importation webdriver # pip install selenium-wire proxy_options = {'proxy ': {'http ': 'http: //USERNAME: PASSWORD @ PROXY_HOST: PROXY_PORT ', 'https ': 'https: //USERNAME: PASSWORD @ PROXY_HOST: PROXY_PORT ', 'no_proxy ': 'localhost,127.0.0.1'}} driver = webdriver.Chrome (seleniumwire_options=proxy_options) driver.get (`` https: //www.google.com '') driver.quit ()

Why this approach works well:

  • No browser extensions need
  • Supports quest inspection and modification
  • Compatible with brainless execution and CI/CD pipelines
  • Cleaner apparatus compared to Chrome extensions

Option 2: Using a Chrome Extension with Python Selenium

If can not be used due to project constraints, authenticated proxies can notwithstanding be configured use a Chrome extension. This method mirrors the JavaScript-based access but integrates it into.

The process involves:

  • Creating a Chrome extension that sets proxy configuration and injects authentication credentials
  • Packaging the extension as a ZIP file
  • Loading the extension utilize ChromeOptions in Python

Python code to load the propagation:

from selenium signification webdriver from selenium.webdriver.chrome.options import Options chrome_options = Options () chrome_options.add_extension (`` proxy.zip '') driver = webdriver.Chrome (options=chrome_options) driver.get (`` https: //www.google.com '') driver.quit ()

Crucial considerations for this coming:

  • Chrome must be installed on the execution machine
  • The propagation must be compatible with the Chrome version used
  • Managing multiple proxy servers requires additional logic in the extension
  • CI environments must support Chrome extensions, which can add setup overhead

Choosing the Right Approach

For Python-based Selenium tests, Selenium Wire is generally the preferred solution due to its simplicity, tractableness, and aboriginal support for authenticated proxies. The Chrome extension method is utilitarian only when extension-based authentication is mandatory or when deeper browser-level proxy control is command.

For a elaborate Python-focused guide using Selenium Wire, refer to:

Common Issues with Proxy in Selenium

When working with proxies in Selenium, there are several mutual number that you might find. Here ’ s a fast overview of some of these challenges and tips on how to handle them:

1. Proxy Connection Errors

  • Issue: Sometimes, Selenium might fail to connect to the proxy waiter, resulting in connection errors.
  • Solution: Double-check the proxy scene, include the IP, port, and certification credentials. Ensure that your proxy waiter is up and running.

2. Authentication Problems

  • Issue: When using an authenticated placeholder, Selenium may struggle with address the hallmark prompting, leading to failed connection.
  • Solution: You can automatise the authentication summons using theDesiredCapabilitiesin Selenium to handle authentication seamlessly.

3. Proxy Configuration Not Applied

  • Issue: Sometimes, the proxy settings aren ’ t decently applied, and Selenium continues to use the default network scope.
  • Solution: Make sure that the proxy settings are right configure in your WebDriver option and that the right capableness are set before initiating the test.

4. Slow or Inconsistent Test Execution

  • Issue: Using a procurator can sometimes slack down your tests, particularly if it ’ s routing traffic through remote waiter or hold complex rules.
  • Solution: Test with procurator site closer to your host or network, and consider habituate a fast proxy service like BrowserStack for unseamed cloud-based testing.

5. HTTPS/SSL Issues

  • Issue: If you & # 8217; re utilize an HTTPS proxy, you may run into SSL credentials number where Selenium doesn ’ t trust the proxy ’ s credential.
  • Solution: You can bypass SSL verification in your Selenium configuration, but be cautious, as this might open your tests up to protection exposure.

6. Inconsistent Results Between Local and Cloud Testing

  • Issue: When trade between local environments and cloud platforms like BrowserStack, may bear otherwise, leading to discrepant test results.
  • Solution: Use cloud quiz platforms like, which ply consistent proxy shape across different devices and browsers, secure reliable exam event.

Selenium Proxy tests failing across browser?

BrowserStack eliminates local net limits by running Selenium Proxy tests on real browsers and devices at scale.

Best Practices for Proxy Setup in Selenium

Setting up proxies in Selenium can greatly enhance your testing, but to get the best results, it & # 8217; s important to follow some key best practices. Here are some tips to check smooth proxy apparatus and testing:

1. Use a Reliable Proxy Server

  • Why: A dumb or unreliable proxy can lead to inaccurate test results and long delays.
  • Best Practice: Always choose a high-quality, reliable placeholder supplier. If possible, opt for alocal proxyto reduce latency or use a service like for cloud-based placeholder examination, which guarantee a stable connection.

2. Automate Proxy Authentication

  • Why: Manually handling proxy certification during tests can be time-consuming and prone to mistake.
  • Best Practice: Automate proxy hallmark utilizeSelenium WebDriver & # 8217; s DesiredCapabilitiesor creature like BrowserMob Proxy. This allows seamless authentication during tests without manual intervention.

3. Configure Proxy Settings Before Starting the Test

  • Why: Changing proxy settings mid-test can lead to inconsistent results or failed exam.
  • Best Practice: Always configure your proxy settings before launch the browser. This ensures that all web petition during the tryout go through the proxy, providing coherent and reliable results.

4. Use Different Proxies for Different Tests

  • Why: Testing with the like proxy for all scenarios can set the diversity of your test suit.
  • Best Practice: For more full-bodied examination, use different proxy to simulate different user locations, web, and conditions. This can be especially helpful for geolocation examination, network limitation, or.

Talk to an Expert

5. Monitor and Log Proxy Traffic

  • Why: Proxy traffic can help you place potential issues, such as network failure or slow response times.
  • Best Practice: Set up logging and monitoring for proxy traffic to capture HTTP requests and reaction. This helps analyze meshwork behavior, name performance bottlenecks, and read how applications interact with backend service during test execution.

6. /HTTPS Proxies Carefully

  • Why: SSL verification matter can interrupt tests when using an HTTPS proxy.
  • Best Practice: If testing on an HTTPS proxy, create sure to either disable SSL verification in your WebDriver or import the procurator & # 8217; s SSL certificate into your browser ’ s reliance store. This ensures secure communicating during the test.

Read More:

7. Consider Using Cloud-Based Testing Platforms

  • Why: Configuring proxies topically can be complex and time-consuming, especially across different browsers and device.
  • Best Practice: Use cloud-based testing platform likeBrowserStack, which simplify proxy frame-up and grant you to test across existent devices and browser without vex about local configuration.

8. Keep Proxy Settings Secure

  • Why: Hardcoding sensitive proxy credentials in your code can unwrap them to unauthorized access.
  • Best Practice: Store procurator credentials securely, using environment variable or secure vault to forbid leak of sensible information. Avoid hardcoding them forthwith into test book.

9. Test Proxy Performance

  • Why: A dull placeholder can significantly affect test executing clip and skew your answer.
  • Best Practice: Periodically quiz the performance of the procurator you use. If you remark a significant drop in speeding or reliability, consider switching to a better-performing proxy provider.

provides a cloud-based solution that offers fast and reliable proxy configurations across a wide orbit of real devices and browser. By testing onBrowserStack & # 8217; s platform, you can check your proxies are performing optimally without the demand to manage local proxy server, allowing for consistent, high-quality testing in diverse environments.

By following these better praxis, you ’ ll be capable to set up procurator in Selenium more efficiently, ensuring your tests are more accurate, authentic, and realistic. Whether testing on local machine or using cloud platforms likeBrowserStack, proper proxy setup will importantly enhance your examine procedure.

Conclusion

Configuring a proxy in Selenium helps testers simulate different network conditions, improve protection, and bypass restrictions. Whether using standard or authenticated proxies, proper frame-up control seamless mechanisation.

Tags
76,000+ Views

# Ask-and-Contributeabout this topic with our Discord community.

Related Guides

Automate This With SUSA

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.

Try SUSA Free

Test Your App Autonomously

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.

Try SUSA Free