gpt4 book ai didi

selenium - 使用 BrowserMobProxy 进行 Selenium 测试时 Chrome 中的 ERR_EMPTY_RESPONSE

转载 作者:行者123 更新时间:2023-12-04 17:50:00 30 4
gpt4 key购买 nike

我创建了从 Chrome 获取网络流量的简单方法:

 public void saveNetworkTraffic() {
System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir") + "/bin/chromedriver");
String sFileName = "networklog.xar";

BrowserMobProxy proxy = new BrowserMobProxyServer();
proxy.start(0);

Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxy);

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.PROXY, seleniumProxy);

WebDriver driver = new ChromeDriver(capabilities);
WebDriverRunner.setWebDriver(driver);

proxy.enableHarCaptureTypes(CaptureType.REQUEST_CONTENT, CaptureType.RESPONSE_CONTENT);

proxy.newHar("google.com");

driver.get("http://google.com/");
Har har = proxy.getHar();

File harFile = new File(sFileName);
try {
har.writeTo(harFile);
} catch (IOException ex) {
System.out.println(ex.toString());
System.out.println("Could not find file " + sFileName);
}
}

当浏览器打开页面时显示错误“ERR_EMPTY_RESPONSE”在这一步 driver.get("http://google.com/") 而不是 Chrome 中通常的谷歌页面。我试图找出错误的原因,但根据 https://github.com/lightbody/browsermob-proxy#using-with-selenium ,我的代码应该可以正常工作。

最佳答案

添加这段代码,试试看:

proxy.addFirstHttpFilterFactory(new ResponseFilterAdapter.FilterSource(new ResponseFilter() {
@Override
public void filterResponse(HttpResponse response, HttpMessageContents contents, HttpMessageInfo messageInfo) {}}, Integer.MAX_VALUE));

enter image description here

关于selenium - 使用 BrowserMobProxy 进行 Selenium 测试时 Chrome 中的 ERR_EMPTY_RESPONSE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45760890/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com