我一直在玩 selenium 并尝试运行 Internet Explorer 11,但出现以下错误。
Started InternetExplorerDriver server (32-bit)
3.1.0.0
Listening on port 25172
Only local connections are allowed
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl. java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.pccw.bpss.qa.automation.Application.execute_Actions(Application.java:79)
at com.pccw.bpss.qa.automation.Application.executeTestCase(Application.java:71)
at com.pccw.bpss.qa.automation.Application.main(Application.java:51)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: org.openqa.selenium.SessionNotCreatedException: Unable to
create new remote session. desired capabilities = Capabilities
[{ie.ensureCleanSession=true}], required capabilities = Capabilities [{}]
Build info: version: '3.1.0', revision: 'b94c902', time: '2017-02-16
12:21:31 -0800'
System info: host: 'PC81013161', ip: '10.37.210.32', os.name: 'Windows
10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_92'
Driver info: driver.version: InternetExplorerDriver at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:91)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:141)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:241)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:227)
at org.openqa.selenium.ie.InternetExplorerDriver.run(InternetExplorerDriver.java:182)
at org.openqa.selenium.ie.InternetExplorerDriver.<init> (InternetExplorerDriver.java:174)
at org.openqa.selenium.ie.InternetExplorerDriver.<init>(InternetExplorerDriver.java:150)
at com.pccw.bpss.qa.automation.execution.ActionKeywords.openBrowser(ActionKeywords.java:45)
... 12 more
我已经尝试过运行 Firefox,它运行良好。我也尝试过修改 IE 的安全功能,但我仍然得到同样的错误。
下面是发生错误的代码片段。初始化 InternetExplorerDriver() 时发生错误
System.setProperty(KEY_IE_DRIVE, FILE_PATH_DRIVER_IE_X32_EXE);
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION, true);
driver = new InternetExplorerDriver(cap);
driver.manage().window().maximize();