How to set Proxy in Firefox using Selenium WebDriver?

On This Page Setting up Firefox Proxy use SeleniumMarch 21, 2026 · 4 min read · Tool Comparison

How to set Proxy in Firefox using Selenium WebDriver?

Internet bandwidth is an important asset, especially at work where multiple resource use the same network simultaneously. High-speed cyberspace enables work to be completely faster and more efficiently. This is especially true when working with web coating, where the net is actively utilise.

Setting up Proxy Servers makes the system quicker by press traffic, deal hoard data, and frequently visited web pages. This heighten internet hurrying and lessen page loading speed importantly.

The placeholder waiter is an entity between the client and the server. Whenever placing asking, the entire traffic from the server flows to the client via the proxy host. Setting up the proxy server while testing a web application on could be helpful in captivate traffic.

Proxy servers let the user access the URL of the, despite the complex topologies of the web. This network at the work complies with the strict insurance and thus has many restrictions that hinders try web applications on it.

This could likewise mock the backend postulation cry make by the web covering under tryout, which could be useful in the testing process.

While running a test, it is all-important to set the proxy settings of the browser, since the WebDriver launch the browser all over again, every time a test is run. However, each time the browser is launched, the proxy settings readjust automatically and need to be readjust every time.

Read More:

This article discusses the various methods by which to manage proxy settings in Selenium WebDriver.

Setting up Firefox Proxy using Selenium

Setting up a Firefox placeholder in Selenium allows you to route browser traffic through a specific placeholder host, which can be useful for testing network conditions, geolocation testing, or cover the actual IP.

This is attain by configuring Firefox & # 8217; s proxy settings through Selenium WebDriver. Using specific preferences, you can specify the proxy speech and port for HTTP, HTTPS, and other protocols. It provides flexibility in control network behavior during automated tests.

There are 3 ways of setting up Firefox Proxy using Selenium

Methods of lay up Firefox Proxy expend Selenium

SUSA automates exploratory testing with persona-driven behavior, catching bugs that scripted automation misses.

  1. By adding preferred Proxy Server Host and Port details toFirefoxOptionsclass, that can be subsequently use in the tests.
  2. By setting Firefox Profile usingFirefoxProfile class.
  3. By position up Desired Capabilities utilise BrowserStack Automate

Method 1. Using FirefoxOptions Class

The following code sets up Proxy by utilize Class FirefoxOptions:

import org.openqa.selenium.Proxy; import org.openqa.selenium.WebDriver; meaning org.openqa.selenium.firefox.FirefoxDriver; significance org.openqa.selenium.firefox.FirefoxOptions; public class proxyTest {public unchanging vacuum main (String [] args) {Proxy placeholder = new Proxy (); //Adding the desired host and port for the http, ssl, and ftp Proxy Servers severally proxy.setHttpProxy (`` & lt; HOST: PORT & gt; ''); proxy.setSslProxy (`` & lt; HOST: PORT & gt; ''); proxy.setSslProxy (`` & lt; HOST: PORT & gt; ''); proxy.setFtpProxy (`` & lt; HOST: PORT & gt; ''); FirefoxOptions options = new FirefoxOptions (); options.setCapability (`` proxy '', proxy); //Calling new Firefox profile for trial WebDriver driver = new FirefoxDriver (options); driver.get (`` https: //www.browserstack.com/ ''); driver.manage () .window () .maximize (); driver.quit ();}}

Method 2. Using FirefoxProfile Class

Similar to the previous method, one can also set Firefox Proxy in Selenium using FirefoxProfile Class. Use the code below to do it:

significance org.openqa.selenium.Proxy; import org.openqa.selenium.WebDriver; importee org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.firefox.FirefoxProfile; public grade proxyTest {public static void main (String [] args) {Proxy placeholder = new Proxy (); //Adding the desired legion and porthole for the http, ssl, and ftp Proxy Servers respectively proxy.setHttpProxy (`` & lt; HOST: PORT & gt; ''); proxy.setSslProxy (`` & lt; HOST: PORT & gt; ''); proxy.setSslProxy (`` & lt; HOST: PORT & gt; ''); proxy.setFtpProxy (`` & lt; HOST: PORT & gt; ''); FirefoxProfile profile = new FirefoxProfile (); profile.setProxyPreferences (proxy); //Calling new Firefox profile for test WebDriver driver = new FirefoxDriver (profile); driver.get (`` https: //www.browserstack.com/ ''); driver.manage () .window () .maximize (); driver.quit ();}}

Also Read:

Talk to an Expert

Method 3. Using Desired Capabilities

Similarly one can besides set Proxy in Firefox utilise Selenium Webdriver, through its.

signification java.io.IOException; importation 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; public form proxyTest {public static void main (String [] args) {Proxy procurator = new Proxy (); //Adding the desired host and port for the http, ssl, ftp Proxy Servers respectively proxy.setHttpProxy (`` & lt; HOST: PORT & gt; ''); proxy.setSslProxy (`` & lt; HOST: PORT & gt; ''); proxy.setSslProxy (`` & lt; HOST: PORT & gt; ''); proxy.setFtpProxy (`` & lt; HOST: PORT & gt; ''); DesiredCapabilities dc = new DesiredCapabilities (); dc.setCapability (CapabilityType.PROXY, proxy); //Calling new Firefox profile for examination WebDriver driver = new FirefoxDriver (dc); driver.get (`` https: //www.browserstack.com/ ''); driver.manage () .window () .maximize (); driver.quit ();}}

BrowserStack allows its users to set Desired Capabilities through as shown below.

Run Selenium Tests on Cloud for Free

Testing Website on Local Environment

Testing websites that are on is always a toughened job, and it command setting up of Proxy Server. However, BrowserStack allows testing of individual websites using its feature. BrowserStack ’ s offers 3500+ existent browsers and devices for manual and automated testing. The latter is accomplished via a. The cloud likewise provides integrations with popular CI/CD puppet such as Jira,, and lots more. Additionally, there are in-built that let examiner identify and adjudicate bugs immediately. BrowserStack also facilitates on 30+ browser adaptation with exigent, hassle-free parallelization.

By Settingbrowserstack.localpotentiality totruein the test book, to test localhost websites. Then, put the following code snippet in the tryout playscript to

bsLocalArgs.put (`` proxyHost '', `` 127.0.0.1 ''); bsLocalArgs.put (`` proxyPort '', `` 8000 '');

Start using BrowserStack Local!

Tags
68,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