我试图设置browsermob在我的硒项目中工作。我一直在寻找一种使用ChromeOptions设置代理的方法,但是所有消息来源都告诉我在所有其他示例中都使用ChromeOptions,然后在实例化新的ChromeDriver实例之前将其转换为DesiredCapabilities。
这是我的代码:
ChromeOptions options = new ChromeOptions();
// Setting some chrome features here
ProxyServer proxyServer = new ProxyServer(4444);
proxyServer.start();
Proxy proxy = proxyServer.seleniumProxy();
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
capabilities.setCapability(CapabilityType.PROXY, proxy);
WebDriver driver = new ChromeDriver(capabilities); // Error happens here
我正在使用来自Maven存储库的Webdriver 2.44版。这是我得到的错误:
java.lang.IllegalAccessError: tried to access field com.google.gson.JsonNull.INSTANCE from class org.openqa.selenium.remote.BeanToJsonConverter
有谁知道将代理连接到chromedriver的原因或任何其他解决方案?
如果您使用的是旧版的browsermob-proxy,则Selenium的依赖项和BMP的依赖项之间可能会有一些冲突。我建议使用最新的Selenium +从主版本构建最新的BrowserMob代理。
拥有最新版本后,您应该能够以“常规”方式使用Chrome + BMP:
BrowserMobProxy proxy = new BrowserMobProxyServer();
proxy.start(); // can specify a port here if you like
// get the selenium proxy object
Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxy);
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.PROXY, seleniumProxy);
// if chromedriver isn't on your system path, you'll need to set this system property
System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");
WebDriver driver = new ChromeDriver(capabilities);
driver.get("https://www.google.com/");
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句