如何在 Java 的 Selenium 中处理代理?
software testingautomation testingselenium web driver
我们可以借助 PROXY 类在 Java 的 Selenium 中处理代理。
import java.io.IOException;
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 自动生成的方法存根
WebDriver driver;
String prox = "localhost:8080";
// 使用所需功能设置浏览器设置
Proxy p = new Proxy(); p.setHttpProxy(prox).setFtpProxy(prox).setSslProxy(prox)
.setSocksProxy(prox);
DesiredCapabilities c = new DesiredCapabilities();
c.setCapability(CapabilityType.PROXY, p);
// 利用启动浏览器驱动程序的功能
driver = new Firefox(c);
}
}

