如何在硒中使用IEDriver?

时间:2017-03-08 01:59:23

标签: java selenium selenium-iedriver

我一直在玩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();

1 个答案:

答案 0 :(得分:3)

查看以下内容是否有帮助:

  1. 转到“Internet选项”
  2. 安全
  3. 点击:&#34;将所有区域重置为默认级别&#34;
  4. 勾选&#34;启用保护模式&#34;所有区域的复选框