Skip to content

seleniumQuery and IE Driver

Antônio "acdc" Jr edited this page May 3, 2018 · 12 revisions

This wiki page is about seleniumQuery and IE (Internet Explorer) as Driver/WebDriver/Browser.


Firstly, make sure you check the InternetExplorerDriver page on selenium wiki, specially the Required Configuration part - if you go through it, you most likely won't run into trouble!


Using Internet Explorer as WebDriver in seleniumQuery


Simplest alternative: let seleniumQuery download and configure the driver for you

$.driver()
    .useInternetExplorer() // sets Internet Explorer as the driver
    .autoDriverDownload() // automatically downloads and configures IEDriverServer.exe
    .autoQuitDriver(); // automatically quits the driver when the JVM shuts down

// now use normally
$.url("http://www.google.com/?hl=en");
$(":text[name='q']").val("seleniumQuery"); // the keys are actually typed!
$(":button[value='Google Search']").waitUntil().isVisible().then().click();

To get the latest version of seleniumQuery, add to your pom.xml:

<dependency>
    <groupId>io.github.seleniumquery</groupId>
    <artifactId>seleniumquery</artifactId>
    <version>0.19.0</version>
</dependency>



If you already have IEDriverServer.exe downloaded and want to use it

Download the latest IEDriverServer.exe release at http://selenium-release.storage.googleapis.com/index.html and place it:

  • (1) on the classpath of your project; or

  • (2) on the path specified by the webdriver.ie.driver system property; or

  • (3) on a folder in the system's PATH variable; or

  • (4) wherever and set the path via

    // using seleniumQuery to instantiate IE with the .exe not on the path or classpath
    $.driver().useInternetExplorer().withPathToIEDriverServerExe("other/path/to/IEDriverServer.exe");
    // then proceed as usual...
    $.url("http://www.google.com");
    ...

If you are using other framework or already have an instance of the driver, just do:

// a previously built/started WebDriver
WebDriver ieDriver = new InternetExplorerDriver();

// can be decorated by seleniumQuery right away, with no side-effects to your current environment
$.driver().use(ieDriver);
// then proceed as usual...
$.url("http://www.google.com");
...



Full program example

import static io.github.seleniumquery.SeleniumQuery.$; // this will allow the short syntax

public class SeleniumQueryExample {
  public static void main(String[] args) {
    // sets InternetExplorer as the driver
    $.driver()
      .useInternetExplorer() // sets Internet Explorer as the driver
      .autoDriverDownload() // automatically downloads and configures IEDriverServer.exe
      .autoQuitDriver(); // automatically quits the driver when the JVM shuts down

    $.url("http://www.google.com/?hl=en");

    $(":text[name='q']").val("selenium"); // the keys are actually typed!
    $(":button:contains('Google Search')").click();
    // Another way: $(":text[name='q']").val("selenium").submit();

    // Besides the short syntax and the jQuery behavior you already know,
    // other very useful function in seleniumQuery is .waitUntil(),
    // handy for dealing with user-waiting actions (specially in Ajax enabled pages):
    String resultsText = $("#resultStats").waitUntil().is(":visible").then().text();
    System.out.println(resultsText);
  }
}





Throubleshooting InternetExplorerDriver

IE Driver has some very frequent exceptions; those are not related to seleniumQuery, but from the driver itself. You'll find some guidelines on how to solve them below.


Protected Mode exception while launching IE Driver

The message could be like:

Unexpected error launching Internet Explorer. Protected Mode must be set to the same value (enabled or disabled) for all zones.

Or:

org.openqa.selenium.remote.SessionNotFoundException: Unexpected error launching Internet Explorer. Protected Mode settings are not the same for all zones. Enable Protected Mode must be set to the same value (enabled or disabled) for all zones. (WARNING: The server did not provide any stacktrace information)

Some solutions are found below.

Change the Protected Mode in all zones

And as stated in https://code.google.com/p/selenium/issues/detail?id=1795, in IE, go to Tools -> Internet Options -> Security Tab and set all zones to the same protected mode (can be enabled or disabled).

Security zones

This is also explained in a stackoverflow answer:

It needs to set same Security level in all zones. To do that follow the steps below:

  1. Open IE
  2. Go to Tools -> Internet Options -> Security
  3. Set all zones to the same protected mode, enabled or disabled should not matter.

Finally, set Zoom level to 100% by right clicking on the gear located at the top right corner and enabling the status-bar. Default zoom level is now displayed at the lower right.


If you can't change the security level:

System.setProperty("webdriver.ie.driver", IEDriverLocation);
DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();
ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
WebDriver ieDriver = new InternetExplorerDriver(ieCapabilities);
$.driver().use(ieDriver);

But be warned this can make your driver close/break/fault for no apparent reason.



Zoom level error while launching Internet Explorer

The exception would be as follows:

org.openqa.selenium.remote.SessionNotFoundException: Unexpected error launching Internet Explorer. Browser zoom level was set to 75%. It should be set to 100% (WARNING: The server did not provide any stacktrace information)

Fix: The easiest solution is to open IE manually, set the Zoom level to 100% (hit CTRL+0 or go through the menu).

Additionally, you could attempt to create the InternetExplorerDriver manually ignoring the zoom setting:

System.setProperty("webdriver.ie.driver", IEDriverLocation);
DesiredCapabilities caps = DesiredCapabilities.internetExplorer();
caps.setCapability("ignoreZoomSetting", true);
WebDriver ieDriver = new InternetExplorerDriver(caps);
$.driver().use(ieDriver);



Unable to get browser

This is one of the worst errors, as it gives no clue about what is happening.

If you get a:

org.openqa.selenium.NoSuchWindowException: Unable to get browser (WARNING: The server did not provide any stacktrace information)

Right off the start of the driver,

Fix: Have you set all your protected mode to the same value (as explained above)? If the answer is yes, then try setting them all to DISABLED.

If that didn't solve the problem, make sure you go follow all the steps in the Required Configuration part of the selenium IE Driver wiki.



NoSuchWindowException: Currently focused window has been closed.

When you attempt to interact with a selenium element, you get:

Exception in thread "main" org.openqa.selenium.NoSuchWindowException: Currently focused window has been closed.

Make sure you have changed the protected mode (see above: https://github.com/seleniumQuery/seleniumQuery/wiki/seleniumQuery-and-IE-Driver#change-the-protected-mode-in-all-zones).

Also, again, did you execute all steps of the Required Configuration?

In case you are in doubt, the last point:

  • For IE 11 only, you will need to set a registry entry on the target computer so that the driver can maintain a connection to the instance of Internet Explorer it creates. For 32-bit Windows installations, the key you must examine in the registry editor is HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE. For 64-bit Windows installations, the key is HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE. Please note that the FEATURE_BFCACHE subkey may or may not be present, and should be created if it is not present. Important: Inside this key, create a DWORD value named iexplore.exe with the value of 0.

Is the same as executing a .reg file with this content (example for the windows 64 bits above):

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE]
"iexplore.exe"=dword:00000000



InvalidSelectorException: "The xpath expression ... cannot be evaluated or does notresult in a WebElement"

This error also manifestates as:

Internet Explorer restricted this webpage from running scripts or ActiveX controls.

If you are using XPath (which seleniumQuery does), or similar cases, the exception above may rise if the HTML page is a local file.

In that case, follow the steps below to fix it:

  • On Internet Explorer, go to Tools (top right corner) -> Internet Options
  • Open the Advanced tab
  • Look for the Security group and check "Allow active content to run in files on My Computer*", as shown in the screenshot below:

Enable ActiveX Locallye on IE



More info

If you feel there's anything seleniumQuery can do to help or make the configuration of the InternetExplorerDriver easier (such as capturing the exceptions and rethrowing with better explanation, or any in other way), go ahead and open an issue.

As you may find out, IE Driver occasionally may show some erros. You can find more info on:

Run Protractor Against Internet Explorer VM, a blog post about the IE Driver, with some good and useful screenshots.