0

我已将 IE 驱动程序更新到 3.12.0.0,但它无法正常工作。我收到以下错误消息

代码:

DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION, true);
System.setProperty("webdriver.ie.driver", "C:\\iedriver\\IEDriverServer.exe");
WebDriver driver = new InternetExplorerDriver(cap);
driver.manage().window().maximize();
driver.manage().deleteAllCookies();

来自控制台的错误消息

Unable to create new remote session. desired capabilities = Capabilities [{ie.ensureCleanSession=true}], required capabilities = Capabilities [{}]
4

1 回答 1

0

你快到了。您需要使用MutableCapabilities类中的方法merge()方法将DesiredCapabilities类型的对象合并到InternetExplorerOptions类型的对象中,并通过传递InternetExplorerOptions对象来启动WebDriverWebClient实例,如下所示:

System.setProperty("webdriver.ie.driver", "C:\\iedriver\\IEDriverServer.exe");
DesiredCapabilities cap = DesiredCapabilities.internetExplorer();
cap.setCapability(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION, true);
InternetExplorerOptions options = new InternetExplorerOptions()
options.merge(cap);
WebDriver driver = new InternetExplorerDriver(options);

PS:作为参考,您可以查看mutablecapabilities标签中的讨论

于 2018-06-04T19:08:42.033 回答