Using Selenium in the Proxy

Selenium, an open-source software, provides a portable automated-testing framework for HTTP requests. Selenium includes a playback tool for users to author functional tests without needing to know a test scripting language.

The WebDriver feature, included in Selenium as of version 2.0, provides the WebDriver API, a platform- and language-neutral wire protocol. 

This enables users to write instruction sets to run interchangeably on most web browsers now in use. Selenium can be deployed on Windows, Linux and macOS.

This article describes configuration of Selenium for use in several popular programming languages and major browsers. Though Selenium comes with a test domain-specific language, called Selenese, you can also create tests in most scripting languages commonly used for ProxyMesh requests.

You can use any URL/hostname you already have access to for Selenium.

For web browsers, you must use IP address authentication, then configure your network proxy settings. If you use Firefox or Chrome, the FoxyProxy plugin makes it very easy to configure your proxy settings.

Regarding web browsers, you'll find additional information in our article How to Change Web Browser Proxy Settings.



Selenium in C#

You'll find download and installation instructions at The Selenium Browser Automation Project. For automated testing, Visual Studio contains WebDriver's C# language bindings. Many users select NUnit as their testing framework. You'll also need the ChromeDriver executable.

Browsers with Selenium in C#

The Most Complete Selenium WebDriver C# Cheat Sheet includes basic and advanced browser settings for Selenium in C#.


Selenium in Java

Here's a link to installation instructions for Selenium with Java.

To use Selenium and Java with ProxyMesh, see these 2 links for examples:

The following example is from
Launching chrome driver with proxy settings in Selenium WebDriver java

Browser Configuration for Selenium in Java

How to launch chrome driver with proxy server
import org.openqa.selenium.Proxy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;

public class ChromeAutomationExtension {
  public static void main(String[] args) {
    System.setProperty(“”, “C:\\selenium\\chromedriver.exe”);
    Proxy proxy = newProxy(); 

    DesiredCapabilities capabilities =; 
    capabilities.setCapability(“proxy”, proxy);

    ChromeOptions options = newChromeOptions();
    capabilities.setCapability(ChromeOptions.CAPABILITY, options);

    WebDriver driver = newChromeDriver(capabilities); 
Proxy Settings Summary
  • proxy.setProxyType(proxyType) ==> Indicates the type of proxy configuration.
  • values are: “pac”, “direct”, “autodetect”, “system”, or “manual”.
  • proxy.setProxyAutoconfigUrl(proxyAutoconfigUrl) ==> Defines the URL for a proxy auto-config file if proxyType is equal to “pac”.
  • values are: any valid URL
  • proxy.setHttpProxy(“”) ==> Defines the proxy host for HTTP traffic when the proxyType is “manual”.
  • values are: A host and optional port for scheme “http”.
  • proxy.setNoProxy(noProxy) ==> Lists the address for which the proxy should be bypassed when the proxyType is “manual”.
  • values are: A List containing any number of Strings.
  • A proxyType of “direct” indicates that the browser should not use a proxy at all.
  • A proxyType of “system” indicates that the browser should use the various proxies configured for the underlying Operating System.
  • A proxyType of “autodetect” indicates that the proxy to use should be detected in an implementation-specific way.
Example to set proxy for Firefox driver instance

import org.openqa.selenium.Proxy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class ProxySettings {
  WebDriver driver;

  public void setUpDriver() {
    //Set proxy IP and port. Here PROXYHOST Is proxy IP and PORT Is Port number.
    //You can change both values as per your requirement.
    //Below given syntaxes will set browser proxy settings using DesiredCapabilities.
    Proxy proxy = newProxy(); 
    DesiredCapabilities cap = newDesiredCapabilities(); 
    cap.setCapability(CapabilityType.PROXY, proxy);
    //Use Capabilities when launch browser driver Instance. 
    driver = newFirefoxDriver(cap);

  public void start() throws IOException {
    System.out.println("Check your webdriver driver Instance's proxy setttings.");


Selenium in JavaScript

This Selenium JavaScript takes you to a tutorial on installing and configuring Selenium in JavaScript.

You can use Selenium and JavaScript together, along with nodejs, to run tests across most popular browsers.

If you are using nodejs to develop your application, the Selenium Project provides JavaScript bindings on npm.

Use the following command to install the JavaScript bindings with npm:
npm install selenium-webdriver

The blog Selenium + JavaScript Best Practices offers tips on combining them for best results, as well as for test-writing in Selenium.

Here is a link to the API docs.

Browser Configuration for Selenium in JavaScript

You can use Selenium and JavaScript together, along with nodejs, to run tests across most popular browsers.

The blog Selenium + JavaScript Best Practices offers tips on combining them for best results, as well as test writing in Selenium.

To use JavaScript with Selenium, you will need to download additional components to work with each of the major browsers. The drivers for Chrome, Firefox, and Microsoft's IE and Edge web browsers are all standalone executables that should be placed on your system path. Apple's safaridriver is shipped with Safari 10 for OS X El Capitan and macOS Sierra. You will need to enable Remote Automation in the Develop menu of Safari 10 before testing.

Browser Component
Chrome chromedriver(.exe)
Edge MicrosoftWebDriver.msi
Firefox geckodriver(.exe)
Internet Explorer IEDriverServer.exe
Safari safaridriver


Selenium in Perl

Follow this GitHub link for information on installing and using Selenium WebDriver with Perl.

Metacpan, an archive for the Comprehensive Perl Archive Network, provides additional usage examples here.

Browser Configuration for Selenium in Perl

Firefox & Chrome

To configure the web browser to use with Perl, follow this link to GitHub for steps to install Firefox (older and newer versions) and Chrome.

The link also lists PhantomJS, but be aware that PhantomJS is currently suspended and archived.
When the browser(s) are installed and you have the appropriate binary in your path, you should be able to do the following:
my $firefox =Selenium::Firefox->new; 
my $chrome = Selenium::Chrome->new; 
my $ghost = Selenium::PhantomJS->new; 


Selenium in PHP

The PHP language bindings are designed to work in PHPUnit, a unit testing framework for the PHP language.

Bindings are provided by the following third parties:

Please refer to their respective documentation sites, on the above links, for steps to install and get started.

Browser Configuration for Selenium in PHP

The BrowserStack page for Selenium with PHP provides technical detail, including downloads for language bindings and settings for several versions of major browsers.


Selenium in Python

To add Selenium to your Python environment, you must install Pip, the package installer for Python. Pip also has a dependency on setuptools.

Then add Selenium to your Python environment, by running the following from a command-line:
pip install selenium

Browser Configuration for Selenium in Python


To configure the Python WebDriver for Selenium to use Chrome, see  Installing Selenium WebDriver Using Python and Chrome.

Also see answer 5 in how do i set proxy for chrome in python webdriver.

Here is a code sample from Selenium Import WebDriver.
chrome_options = webdriver.ChromeOptions() 
chrome_options.add_argument('--proxy-server=%s' % PROXY) 
chrome = webdriver.Chrome(options=chrome_options) 
To configure the network proxy settings for Selenium to use Firefox, you can do something like this: 
profile = webdriver.FirefoxProfile()
profile.set_preference("network.proxy.type", 1)
profile.set_preference("network.proxy.http_port", PORT) 
profile.set_preference("network.proxy.ssl", 'HOST') 
profile.set_preference("network.proxy.ssl_port", PORT) 
driver = webdriver.Firefox(firefox_profile=profile)


Selenium in R

For automated testing, the R Studio provides a link to install the Selenium 2.0 WebDriver. The following link takes you to a general how-to: How to drive a Web browser with R (and RSelenium).

The "RSelenium" package, with a complete set of R language bindings for Selenium WebDriver 2.0, is available as a PDF.

Scraping with Selenium discusses a variety of ways R and Selenium can be used together with a proxy.

Browser Configuration for Selenium in R

For configuring your web browser to use R and RSelenium, you’ll find more information in How to drive a Web browser with R (and RSelenium).

For testing, the article referenced above, “How to drive a Web browser with R (and RSelenium)” includes detail on how to set up R Studio to open several different browsers in succession.


Selenium in Ruby

The site Getting Started With Ruby and Selenium offers tutorials for:

  • Installing Ruby on major platforms
  • Installing Ruby libraries
  • Installing Selenium WebDriver
  • Installing ChromeDriver

Browser Configuration for Selenium in Ruby

The BrowserStack page for Selenium with Ruby provides technical detail, including downloads for language bindings and settings for several versions of major browsers.

Custom Headers

Use the X-ProxyMesh-IP to specify a particular IP for the request. This IP should come from the X-ProxyMesh-IP response header of a previous request.


Use the X-ProxyMesh-Prefer-IP header when you want to use a specific IP for a request, but you also want the request to succeed even if the IP is no longer available, in which case a random IP is chosen instead.

See Proxy Server Request & Response Headers for details.
More Information

Please see our blog article Benefits of Browser Automation.

Still need help? Contact Us Contact Us