- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to set Proxy in Firefox using Selenium WebDriver?
We can set a proxy in Firefox using Selenium webdriver. A proxy server enables users to access an URL of an application for testing purposes even with the presence of several layers of network.
The setting up of proxy in Firefox can be done with the help of the FirefoxOptions class. The port information and the proxy server host are added to this class. The setting up of the proxy server can also be done by configuring the Firefox Profile in the FirefoxProfile class.
Example
Code Implementation with the FirefoxOptions
import org.openqa.selenium.Proxy; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.firefox.FirefoxOptions; public class ConfigureProxy { public static void main(String[] args) { //object of Proxy Proxy p = new Proxy(); //adding host and port p.setHttpProxy("<HOST:PORT>"); p.setSslProxy("<HOST:PORT>"); p.setSslProxy("<HOST:PORT>"); p.setFtpProxy("<HOST:PORT>"); //object of FirefoxOptions FirefoxOptions o = new FirefoxOptions(); o.setCapability("proxy", p); //passing Firefox option to webdriver object WebDriver driver = new FirefoxDriver(o); //url launch driver.get("https://www.tutorialspoint.com/index.htm"); //browser close driver.close(); } }
Example
Code Implementation with the FirefoxOptions
import org.openqa.selenium.Proxy; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.firefox.FirefoxProfile; public class ConfigureProxyProfile { public static void main(String[] args) { //object of Proxy Proxy p = new Proxy(); //adding host and port p.setHttpProxy("<HOST:PORT>"); p.setSslProxy("<HOST:PORT>"); p.setSslProxy("<HOST:PORT>"); p.setFtpProxy("<HOST:PORT>"); //object of FirefoxProfile FirefoxProfile pl = new FirefoxProfile(); pl.setProxyPreferences(p); //passing Firefox profile to webdriver object WebDriver driver = new FirefoxDriver(pl); //url launch driver.get("https://www.tutorialspoint.com/index.htm"); //browser close driver.close(); } }
- Related Articles
- How to hide Firefox window (Selenium WebDriver)?
- How does Selenium Webdriver handle SSL certificate in Firefox?
- Handle Firefox Not Responding While Using Selenium WebDriver With Python?
- Running Selenium Webdriver with a proxy in Python.
- How to get Firefox working with Selenium WebDriver on Mac OSX?
- How to set Page Load Timeout using C# using Selenium WebDriver?
- How to set window size using phantomjs and selenium webdriver in Python?
- How can I manually set proxy settings in Python Selenium?
- How to set Selenium Python WebDriver default timeout?
- Where can I find a definitive Selenium WebDriver to Firefox Compatibility Matrix?
- How to Verify Tooltip using Selenium WebDriver?
- How to upload files using Selenium Webdriver?
- How to handle proxy in Selenium in Java?
- How to handle frame in Selenium WebDriver using java?
- How to use clickandwait in Selenium Webdriver using Java?

Advertisements