我正在尝试使用BrowserMobProxy拦截Webdriver发出的请求。

但是以下代码无法正常工作。无法打开网站google.com。

它说“ Internet Explorer无法打开该站点”

    proxyServer = new ProxyServer(9101);
    proxyServer.start();

    proxyServer.setCaptureHeaders(true);
    proxyServer.setCaptureContent(true);

    proxyServer.addRequestInterceptor(new RequestInterceptor() {
        @Override
        public void process(BrowserMobHttpRequest request, Har har) {
            System.out.println("From Process method");
        }
    });

    seleniumProxy = proxy.seleniumProxy();

    seleniumProxy.setHttpProxy("localhost:9101");

    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(CapabilityType.PROXY, seleniumProxy);
    capabilities.setCapability("ie.setProxyByServer", true);

    File file = new File("C:\\path\\IEDriverServer.exe");
    System.setProperty("webdriver.ie.driver", file.getAbsolutePath());

    driver = new InternetExplorerDriver(capabilities);
    driver.get("www.google.com");


尝试从webdrviver访问google.com时出现以下错误

From Process methodNov 09, 2014 2:07:58 AM net.lightbody.bmp.proxy.util.Log infoINFO: java.net.UnknownHostException: www.google.com when requesting http://www.google.com/

最佳答案

Browsermob使用xbill DNS代替常规的Java /本地DNS解析,这可能不适用于您的VPN。最新的browsermob快照允许您通过将系统属性bmp.allowNativeDnsFallback设置为true来启用本机DNS回退:

System.setProperty("bmp.allowNativeDnsFallback", "true");
proxyServer = new ProxyServer(9101);
proxyServer.start();


您可以从browsermob github page获取最新快照。

关于java - 如何使用WebDriver设置BrowserMob?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26824979/

10-09 19:23