使用Chrome浏览器捕获网络调用但获取NoSuchMethodError

时间:2018-06-14 22:06:10

标签: java selenium

以下是使用Chrome浏览器捕获网络调用的代码,但这会引发错误:Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.collect.ImmutableList.toImmutableList()Ljava/util/stream/Collector;

public static void main(String[] args) {
    System.setProperty("webdriver.chrome.driver", "src/test/resources/drivers/chromedriver.exe");


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

    Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxy);

    // configure it as a desired capability
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(CapabilityType.PROXY, seleniumProxy);
    ChromeOptions options = new ChromeOptions();
    options.merge(capabilities);
    WebDriver driver = new ChromeDriver(options);

    // enable more detailed HAR capture, if desired (see CaptureType for the complete list)
    proxy.enableHarCaptureTypes(CaptureType.REQUEST_CONTENT, CaptureType.RESPONSE_CONTENT);

    // create a new HAR with the label "yahoo.com"
    proxy.newHar("yahoo.com");

    // open yahoo.com
    driver.get("http://yahoo.com");

    // get the HAR data
    Har har = proxy.getHar();
}

1 个答案:

答案 0 :(得分:0)

尝试将Guava升级到21.0或更高版本。