How to launch Internet Explorer using Selenium
While launching Internet Explorer using selenium is a tedious job since it involves much of internal security and restrictions. As we have seen earlier on how to launch the Chrome browser by simply setting System property and using simple method ChromeDriver(), Internet Explorer do have such kind of method by which we can easily launch the browser. Below code snippet can launch the Internet Explore browser. One can download IE driver from IE Server Driver .
System.setProperty(“webdriver.ie.driver”, “locale path for IE Server driver\\IEDriverServer.exe”);
WebDriver driver = new InternetExplorerDriver();
Code Explanation:
First line of code will set the System property as webdriver.ie.driver which will point to the local path where we have downloaded IEdriver.exe. Second line of above code snippet will take use of this property and launch the IE browser, Since we know that selenium alone can not launch the browser.
Once the browser successfully launched, one can see below message on console.
Browser Profile:
By setting desired capability for IE we can set the preferred browser profile. This means we can specify how we want IE browser to behave during execution. One can set IE browser profile as follows:
System.setProperty(“webdriver.ie.driver”, “Locale path for IEDriver\\IEDriverServer.exe”);
DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer(); capabilities.setCapability(CapabilityType.BROWSER_NAME, “IE”); capabilities.setCapability(InternetExplorerDriver.UNEXPECTED_ALERT_BEHAVIOR, true);
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);
WebDriver driver = new InternetExplorerDriver(capabilities);
Code Explanation:
- setCapability takes the various capabilities as input variables which are then used by the web driver to launch the application in the desired environment.
- setProperty is used to set the path where the driver is located. Web Driver then locates the required driver.
Comments
Post a Comment