Search code examples
javaseleniumselenium-iedriver

How to use IEDriver in selenium?


I've been playing around with selenium and trying to run Internet Explorer 11, but I'm getting the error below.

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

I've tried it running the Firefox and it works fine. I've also tried modifying the security features of IE but still i get the same error.

Below is the code snippet where the error occurs. The error occurs upon the initialization of 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();

Solution

  • See if the following helps:

    1. Go to Internet Options
    2. Security
    3. Click on: "Reset all zones to default level"
    4. Tick "Enable protected mode" checkbox for all zones