当我在ChromeDriver中使用代理时,我有类别偏差。
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true);
capabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT);
LoggingPreferences logPrefs = new LoggingPreferences();
logPrefs.enable(LogType.BROWSER, Level.ALL);
capabilities.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
if (!Context.getProxy().isEmpty()) {
Proxy proxy = new Proxy();
proxy.setHttpProxy(Context.getProxy());
capabilities.setCapability(CapabilityType.PROXY, proxy);
}
System.setProperty(Driver.CHROME.getDriverName(), pathWebdriver);
return new ChromeDriver(capabilities);
如果Context.getProxy()。isEmpty()= true,我的Web驱动程序没问题,但是如果我设置代理我有这个错误:
org.openqa.selenium.WebDriverException: Unable to convert: Capabilities [{ensureCleanSession=true, proxy=Proxy(manual, http=renn.proxy.corp.xxxx:8080), loggingPrefs=org.openqa.selenium.logging.LoggingPreferences@5df041, browserName=chrome, version=, platform=ANY, unexpectedAlertBehaviour=accept}]
at org.openqa.selenium.remote.BeanToJsonConverter.convert(BeanToJsonConverter.java:69)
...
...
Caused by: org.openqa.selenium.WebDriverException: Unable to convert: Capabilities [{ensureCleanSession=true, proxy=Proxy(manual, http=renn.proxy.corp.xxxx:8080), loggingPrefs=org.openqa.selenium.logging.LoggingPreferences@5df041, browserName=chrome, version=, platform=ANY, unexpectedAlertBehaviour=accept}]
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
System info: host: 'ITEM-72885', ip: '192.168.84.9', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_66'
Driver info: driver.version: ChromeDriver
at org.openqa.selenium.remote.BeanToJsonConverter.convertObject(BeanToJsonConverter.java:88)
at org.openqa.selenium.remote.BeanToJsonConverter.convert(BeanToJsonConverter.java:66)
... 84 more
Caused by: java.lang.ClassCastException: java.util.HashMap cannot be cast to java.lang.String
at org.openqa.selenium.remote.BeanToJsonConverter.convertObject(BeanToJsonConverter.java:223)
at org.openqa.selenium.remote.BeanToJsonConverter.convertObject(BeanToJsonConverter.java:143)
at org.openqa.selenium.remote.BeanToJsonConverter.convertObject(BeanToJsonConverter.java:189)
at org.openqa.selenium.remote.BeanToJsonConverter.convertObject(BeanToJsonConverter.java:86)
... 85 more
答案 0 :(得分:0)
升级驱动程序版本时问题已解决。