How to handle proxy in Selenium in Java?

Software TestingAutomation TestingSelenium Web Driver

We can handle proxy in Selenium in Java with the help of PROXY class.

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;
public class ProxySelJav {
   public static void main(String[] args) {
      // TODO Auto-generated method stub
      WebDriver driver;
      String prox = "localhost:8080";
      // set browser settings with Desired Capabilities
      Proxy p = new Proxy(); p.setHttpProxy(prox).setFtpProxy(prox).setSslProxy(prox)
      DesiredCapabilities c = new DesiredCapabilities();
      c.setCapability(CapabilityType.PROXY, p);
      // utilize capabilities on launching browser driver
      driver = new Firefox(c);
Published on 11-Jun-2020 15:32:55