无法创建新的远程会话。 desired capabilities = Capabilities [{ie.ensureCleanSession = true}],启动IE时所需的功能

时间:2018-06-04 14:57:59

标签: java selenium-webdriver selenium-iedriver iedriverserver mutablecapabilities

我已将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 [{}]

1 个答案:

答案 0 :(得分:0)

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

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代码

中的讨论