How To Run Microsoft Internet Explorer And Edge In Selenium Webdriver Automation Script

It is very easy to run test cases using Internet Explorer and Edge in selenium webdriver. You can not launch Internet Explorer directly in java but you can use the selenium IE Driver server to communicate with the Internet Explorer instead. This article will tell you how to run Microsoft Internet Explorer and Edge in selenium webdriver and how to fix the errors when using it.

1. What Is Selenium IE Driver Server?

Although there is not any native Internet Explorer implementation in selenium webdriver, but selenium webdriver commands can be directed to Internet Explorer by the IEDriver server.

The IEDriver server is just a bridge between your selenium commands and IE browser. It is implemented in a windows executable file. You should download it first and then add it to your system path before using it.

Go to http://selenium-release.storage.googleapis.com/index.html to download the latest version. Please note you can download the IEDriverServer.zip file from the folder that version number less than 4.0. In this example, I use the IEDriverServer_x64_3.9.0. So I download the zip file and extract it to the local folder C:\Workspace\dev2qa.com\Lib\IEDriverServer_x64_3.9.0.

2. How To Launch Internet Explorer Using Selenium Webdriver.

2.1 Method 1: Set system property webdriver.ie.driver‘s value to IE Driver executable file path.

It is very easy to create and use Internet Explorer in selenium webdriver. You just need to specify the IE Driver executable file path in the system property webdriver.ie.driver and then use InternetExplorerDriver to initiate and manage Internet Explorer like the following.

 String ieDriverFilePath = "C:\\Workspace\\dev2qa.com\\Lib\\IEDriverServer_x64_3.9.0\\IEDriverServer.exe";
 //Specify the executable file path to sysem property.
 System.setProperty("webdriver.ie.driver", ieDriverFilePath);
 //Initiate web browser
 InternetExplorerDriver ieDriver = new InternetExplorerDriver();
 ieDriver.get("http://www.google.com");

You should make your Internet Explorer’s Protected Mode Settings the same value to all zones before running the code above. Otherwise, you may encounter exceptions.

You can follow the below steps to change Protected Mode settings to the same value in IE. Open your Internet Explorer and click Tools —> Internet Options menu item to open the Internet Explorer Internet Options popup window.

Click the Security tab, check the Enable Protected Mode( requires restarting Internet Explorer ) checkbox for all zones ( zones include InternetLocal intranet, Trusted sites, Restricted sites ). Click the OK button to save the changes.

2.2 Method 2: Use IE Driver service builder.

Another way to run Internet Explorer in selenium webdriver is to use IE Driver service builder. You can specify the IEDriver executable file path to the service builder instead of the system property.

You can set a log file also, with a log file you can debug any issue easily. Please read the below java source code.

 String ieDriverFilePath = "C:\\Workspace\\dev2qa.com\\Lib\\IEDriverServer_x64_3.9.0\\IEDriverServer.exe";
 
 //Create server service builder
 InternetExplorerDriverService.Builder ieDriverServiceBuilder = new InternetExplorerDriverService.Builder();
 
 //Start sever on any free and available port.
 ieDriverServiceBuilder.usingAnyFreePort();
 
 //Specify IEDriver executable file.
 ieDriverServiceBuilder.usingDriverExecutable(new File(ieDriverFilePath));
 
 //Specifies log level
 ieDriverServiceBuilder.withLogLevel(InternetExplorerDriverLogLevel.TRACE);
 
 //Specify where log file stored.
 ieDriverServiceBuilder.withLogFile(new File("C:\\Workspace\\dev2qa.com\\logFile.txt"));
 
 //Initiate a service
 InternetExplorerDriverService service = ieDriverServiceBuilder.build();
 
 //Use service object to initiate IEDriver instance
 InternetExplorerDriver ieDriver = new InternetExplorerDriver(service);
 ieDriver.get("http://www.google.com");

3. How To Fix Failed To Connect To Localhost Error With IEDriverServer Error.

Please note, the IEDriverServer version should be the same as the selenium webdirver jar library version. If not the same, it will throw the failed to connect to localhost error like below when execute.

Started InternetExplorerDriver server (64-bit)
3.9.0.0
Listening on port 34462
Only local connections are allowed
org.openqa.selenium.WebDriverException: java.net.ConnectException: Failed to connect to localhost/[0:0:0:0:0:0:0:1]:34462
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: host: 'LAPTOP-9FS71VQM', ip: '192.168.31.134', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '15.0.2'
Driver info: driver.version: InternetExplorerDriver
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:92)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:213)
    at org.openqa.selenium.ie.InternetExplorerDriver.run(InternetExplorerDriver.java:221)
    at org.openqa.selenium.ie.InternetExplorerDriver.<init>(InternetExplorerDriver.java:213)
    at org.openqa.selenium.ie.InternetExplorerDriver.<init>(InternetExplorerDriver.java:150)
    at com.dev2qa.webdriver.ie.IEBasic.StartInternetExplorer(IEBasic.java:21)
    at com.dev2qa.webdriver.ie.IEBasic.main(IEBasic.java:113)
Caused by: java.net.ConnectException: Failed to connect to localhost/[0:0:0:0:0:0:0:1]:34462
    at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.java:247)
    at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:165)
    at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:257)
    at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:135)
    at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:114)
    at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
    at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
    at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
    at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:126)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
    at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200)
    at okhttp3.RealCall.execute(RealCall.java:77)
    at org.openqa.selenium.remote.internal.OkHttpClient.execute(OkHttpClient.java:103)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:105)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:74)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:136)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
    ... 7 more
Caused by: java.net.ConnectException: Connection refused: no further information
    at java.base/sun.nio.ch.Net.pollConnect(Native Method)
    at java.base/sun.nio.ch.Net.pollConnectNow(Net.java:660)
    at java.base/sun.nio.ch.NioSocketImpl.timedFinishConnect(NioSocketImpl.java:549)
    at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:597)
    at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:333)
    at java.base/java.net.Socket.connect(Socket.java:648)
    at okhttp3.internal.platform.Platform.connectSocket(Platform.java:129)
    at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.java:245)
    ... 29 more

The above error message says that the Started InternetExplorerDriver server (64-bit) version is 3.9.0.0, but the selenium webdriver version is 3.141.59, the two versions are not the same. To fix this error, you should download and use the IEDriverServer_3.141.59 version.

4. How To Fix Zoom Error Launching Internet Explorer.

When you use the InternetExplorerDriver to browse a web page, you may encounter an zoom error when launching internet explorer like below.

org.openqa.selenium.SessionNotCreatedException: Unexpected error launching Internet Explorer. Browser zoom level was set to 125%. It should be set to 100%

To fix this error, you can open the internet explorer and click the Options —> Zoom menu item to set the zoom value to 100%. You can also add the below source code before starting the internet explorer.

String ieDriverFilePath = "D:\\Work\\Tool\\IEDriverServer_x64_3.141.59\\IEDriverServer.exe";
             
System.setProperty("webdriver.ie.driver", ieDriverFilePath);
    
// The below code will ignore the internet explorer zoom settings.       
DesiredCapabilities caps = DesiredCapabilities.internetExplorer();   
caps.setCapability("ignoreZoomSetting", true);           
             
//Initiate web browser
InternetExplorerDriver ieDriver = new InternetExplorerDriver(caps);

5. How To Fix Timed Out Waiting For Page To Load Error.

You may also encounter the error org.openqa.selenium.TimeoutException: Timed out waiting for page to load when run internet explorer selenium driver. To fix this error, you should uncheck the Protected Mode settings for all zones follow the below steps.

Click internet explorer Tools —> Internet Options menu item to open the Internet Options popup window. Click the Security tab, uncheck the Enable Protected Mode( requires restarting Internet Explorer ) checkbox for all zones ( zones include InternetLocal intranet, Trusted sites, Restricted sites ). Click the OK button to save the changes.

6. How To Start Selenium IE Driver Server As Standalone Server.

Now you have known how to start and communicate with the IEDriver server in selenium webdriver. But you can also start it as a standalone server, waiting for commands coming from your webdriver actions and pass those commands to Internet Explorer. Webdriver actions include Webdriver.findElement, Webdriver.get etc.

You can start the IEDriver standalone server simply by type IEDriverServer.exe in your extracted directory in the dos window as following.

D:\Work\Tool\IEDriverServer_x64_3.9.0>IEDriverServer.exe
Started InternetExplorerDriver server (64-bit)
3.9.0.0
Listening on port 5555
Only local connections are allowed

If you add -help after the command IEDriverServer.exe, it will list all the IEDriverServer.exe command arguments and descriptions.

D:\Work\Tool\IEDriverServer_x64_3.9.0>IEDriverServer.exe -help
Launches the WebDriver server for the Internet Explorer driver

IEDriverServer [/port=<port>] [/host=<host>] [/log-level=<level>]
               [/log-file=<file>] [/extract-path=<path>] [/silent]
               [/whitelisted-ips=<whitelisted-ips>] [/version]

  /port=<port>  Specifies the port on which the server will listen for
                commands. Defaults to 5555 if not specified.
  /host=<host>  Specifies the address of the host adapter on which the server
                will listen for commands.
  /log-level=<level>
                Specifies the log level used by the server. Valid values are:
                TRACE, DEBUG, INFO, WARN, ERROR, and FATAL. Defaults to FATAL
                if not specified.
  /log-file=<file>
                Specifies the full path and file name of the log file used by
                the server. Defaults logging to stdout if not specified.
  /extract-path=<path>
                Specifies the full path to the directory used to extract
                supporting files used by the server. Defaults to the TEMP
                directory if not specified.
  /silent       Suppresses diagnostic output when the server is started.
  /whitelisted-ips=<whitelisted-ips>
                Comma-separated whitelist of remote IPv4 addresses which
                are allowed to connect to the WebDriver server.
  /version      Displays version information and exits. All other arguments
                are ignored.

7. How To Start IE Driver Server With Different Port Number.

If you want to start the IEDriver server with a port number other than the default port number you can add the port argument to the IEDriverServer.exe command ( IEDriverServer.exe /port=8088 ).

You can also specify the log file path and log level with /log-file, /log-level arguments as below example.

D:\Work\Tool\IEDriverServer_x64_3.9.0>IEDriverServer.exe /port=8088 /log-file=C:\\Workspace\\dev2qa.com\\ieDriverLog.txt /log-level=DEBUG
Started InternetExplorerDriver server (64-bit)
3.9.0.0
Listening on port 8088
Log level is set to DEBUG
Log file is set to C:\\Workspace\\dev2qa.com\\ieDriverLog.txt
Only local connections are allowed

8. How To Connect To Existing IE Driver Server.

Now the standalone IE Driver server is running. You can connect to it in your java code simply by specifying the IE Driver server IP and port number.

//Set IEDriverServer port number.
ieDriverServiceBuilder.usingPort(8088);

//Specify executable file path.
ieDriverServiceBuilder.usingDriverExecutable(new File(ieDriverFilePath));

//Set IEDriver server host ip.
ieDriverServiceBuilder.withHost("localhost")

9. How To Start Microsoft Edge Web Browser In Selenium Webdriver.

Download the Microsoft Edge web browser webdriver from the link https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/#downloads Download the version which fits your Edge browser version, otherwise when you run the selenium source code, it will throw the below error message.

org.openqa.selenium.SessionNotCreatedException: session not created: This version of MSEdgeDriver only supports MSEdge version 92
Current browser version is 90.0.818.46 with binary path C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe

To get your Microsoft Edge browser version, you should open Edge browser, then click the menu item ( on the Edge top right corner ) —> Settings —> About Microsoft Edge.

After download the Microsoft Edge selenium driver zip file, unzip it to a local folder such as D:\Work\Tool\edgedriver_win64\msedgedriver.exe.

Write the below java source code in a java file.

package com.dev2qa.webdriver.ie;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;

public class IEBasic {

    public static void StartEdge() {
        
        try {

             //Specify the executable file path to system property.
             String edgeDriverFilePath = "D:\\Work\\Tool\\edgedriver_win64\\msedgedriver.exe";
             System.setProperty("webdriver.edge.driver", edgeDriverFilePath);

             //Initiate the Microsoft Edge web browser
             EdgeDriver edgeDriver = new EdgeDriver();
            
             //Maximize the edge browser window 
             edgeDriver.manage().window().maximize();
             
             edgeDriver.get("http://www.google.com");
                    
             //Sleep 2 seconds to wait for the page load complete
             Thread.sleep(2000);
                        
             // Get the google search box object by the search box name.
             WebElement searchBox = edgeDriver.findElement(By.name("q"));
             // Input search keyword text in the google search box.
             searchBox.sendKeys("selenium");
            
             // Press the keyboard Enter key to close the search tips drop-down list and search.
             searchBox.sendKeys(Keys.ENTER);
        
             // Get the google search button by the search button name.
             //WebElement searchBtn = edgeDriver.findElement(By.name("btnK"));
             // Click the search button to search.
             //searchBtn.click();
    
             //Print out action success message.
             System.out.println("Open website success.");
            
             //Sleep 10 seconds to wait for the page load complete
             Thread.sleep(10000);
            
             // Quit and close the IE web browser.
             edgeDriver.quit();
        }catch(Exception ex){
            
            ex.printStackTrace();
        }
    }   
    
    
    public static void main(String[] args) {
 
        IEBasic.StartEdge();

    }
}

Right-click the above java file in eclipse maven project editor, click Run As —> Java Application menu item to run it, you can see the Microsoft Edge web browser startup and open google home page and search the keyword selenium and return the search result page.

10. References.

How To Create Maven Project In Eclipse

How To Add Selenium Server Standalone Jar File Into Your Java Project

How To Run Test Cases Using Google Chrome In Selenium Automation Script

How To Use Firefox Webdriver To Launch Firefox Browser Automatically In Java

How To Run Test Cases Using Apple Safari In Selenium Automation Script

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.