Edge IE Mode Example

This selenium java Edge IE mode example opens a test page in internet explorer view.

Example Microsoft Edge IE Mode




import java.io.File;
import java.io.IOException;
import java.net.URL;
import org.openqa.selenium.*;
import org.openqa.selenium.ie.InternetExplorerOptions;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.SessionId;
import org.apache.commons.io.FileUtils;



public class edge_ie_mode {

	//NOTE: find these credentials in your Gridlastic dashboard after launching your selenium grid (get a free account).
	public static String VIDEO_URL = System.getenv("VIDEO_URL"); //like https://s3-us-west-1.amazonaws.com/027a15f2-530d-31e5-f8cc-7ceaf6355377/239a51a9-c526-ceb8-9ffd-1759b782a464/play.html?
	public static String HUB_URL = System.getenv("HUB_URL"); // like "https://USERNAME:ACCESS_KEY@YOUR_SUBDOMAIN.gridlastic.com/wd/hub";


	public static void main(String[] args) throws Exception {

		InternetExplorerOptions options = new InternetExplorerOptions();
		options.attachToEdgeChrome();
		options.withEdgeExecutablePath("C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe");   
		options.setCapability("platformName", "win10");   
		options.setCapability("browserVersion", "11.edge-latest");	        
		options.setCapability("requireWindowFocus", true);
		options.setCapability("ie.ensureCleanSession", true);
		options.setCapability("ignoreZoomSetting", true);
		options.setCapability("nativeEvents", true);
		options.setCapability("ignoreProtectedModeSettings", true);

		// ENABLE VIDEO RECORDING
		// Note: starting with selenium grid version 4.5.2 video recording is enabled by default when testing with internet explorer.
		// options.setCapability("video", true);  OR  options.setCapability("video", "true"); 

		WebDriver driver = new RemoteWebDriver(new URL(HUB_URL),options);
		driver.manage().window().maximize();

		SessionId sessionId = null;
		sessionId = ((RemoteWebDriver) driver).getSessionId();


		try {
			driver.get("https://www.gridlastic.com/");  
			Thread.sleep(10000); // slow down for demo purposes


			//Take a screenshot
			File screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);        
			try {
				FileUtils.copyFile(screenshot, new File("./screenshot.png"));
			} catch (IOException e) {
				System.out.println(e.getMessage());
			}


			System.out.println("Test Video: " + VIDEO_URL + sessionId.toString());
			if(driver != null){
				driver.quit();
			}
		} catch (Exception e) {
			e.printStackTrace();
			driver.quit();
		}



	}

}

We recommend you pre-launch nodes for your Microsoft Edge IE mode testing to minimize timeouts and non deterministic test failures.