
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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(); } }
Advertisements