我正在尝试使用selenium捕获https流量,但无法捕获它。正确捕获了Http流量,但遇到了https流量问题。在chrome和firefox上获取相同的消息
'糟糕
出了点问题。
Firefox出于某种原因无法加载此页面。'
package com.quadanalytix.selenium;
import org.browsermob.proxy.ProxyServer;
import org.openqa.selenium.Proxy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
public class Test2 {
public static void main(String[] args) throws Exception {
ProxyServer server = new ProxyServer(4446);
server.start();
// get the Selenium proxy object
Proxy proxy = new Proxy();
proxy.setSslProxy("localhost:4446");
proxy.setHttpProxy("localhost:4446");
//captures the moouse movements and navigations
server.setCaptureHeaders(true);
server.setCaptureContent(true);
// configure it as a desired capability
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(CapabilityType.PROXY, proxy);
System.setProperty("webdriver.chrome.driver", "/Users/tarunaggarwal/Desktop/Selenium/ChromeDriver");
// start the browser up
WebDriver driver = new ChromeDriver(capabilities);
server.newHar("gmail");
driver.get("https://www.gmail.com/");
server.stop();
driver.quit();
}
}
答案 0 :(得分:0)
为什么要创建新的Java代理对象而不是以下内容?
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(CapabilityType.PROXY, server.seleniumProxy());
您可以使用chrome尝试以下内容:
ChromeOptions options = new ChromeOptions()
options.addArguments("--proxy-server=localhost:4446")
driver = new ChromeDriver(options)