Tony
Tony

Reputation: 1155

Setting compatability mode for IE using Selenium

From an earlier discussion. I am using IE 11 via Selenium and IE driver. The web site I am viewing (I have no control over) needs IE 5 or greater. I am using IE 11. As someone told me, IE 11 returns "Netscape" as the app name instead of "Internet Explorer". My guess is the site is looking for "Internet Explorer".

We are able to overcome this by setting compatibility mode. However, the Jenkins server on which the IE is running is not available for login so I cannot login and set the mode.

I want to set compatability mode when IE comes up. One item mentioned doing ALT-T-Compatability Mode, then filling in the URL and closing. This works fine manually but I am trying to do it automatically. I came up with this code which does not work. Not even the ALT-T works. I think there must be some reason the keys are not being sent correctly:

        WebElement ele = driver.findElement(By.xpath("//html"));
        Actions action = new Actions(driver);
        action.moveToElement(ele).click().build().perform();
        action.sendKeys(Keys.LEFT_ALT).sendKeys("t").build().perform();

        for (int i = 1; i <= 11; i++) {
            action.sendKeys(Keys.DOWN).build().perform();
        }
        action.sendKeys(Keys.ENTER).build().perform();
        action.sendKeys(url).build().perform();
        action.sendKeys(Keys.ENTER).build().perform();
        for (int i = 1; i <= 4; i++) {
            action.sendKeys(Keys.TAB).build().perform();
        }
        action.sendKeys(Keys.ENTER).build().perform();

This is not showing the toolbar or anything it is as though it were being ignored. No exceptions or anything are thrown. So is there a way to do that?

Barring that, is there a way when we set up desired capabilities for the IE driver to specify compatibility mode for a URL, or some other way when we get the driver? I did not see any fields for that.

Keys.chord() will not work either.

Upvotes: 2

Views: 5378

Answers (2)

Shiv
Shiv

Reputation: 9

The below code perfectly worked for me with IE11

public class ieCompatibilityViewSettings {

public static void main(String[] args) throws InterruptedException, AWTException {

    WebDriver driver = new InternetExplorerDriver();
    driver.get("http://gmail.com");
    Thread.sleep(3000);

    Robot rob = new Robot();

    rob.keyPress(KeyEvent.VK_ALT);
    rob.keyPress(KeyEvent.VK_X);
    rob.keyRelease(KeyEvent.VK_X);
    rob.keyRelease(KeyEvent.VK_ALT);

    for (int i = 1; i <= 9; i++) {
        rob.keyPress(KeyEvent.VK_DOWN);
        rob.keyRelease(KeyEvent.VK_DOWN);
    }

    rob.keyPress(KeyEvent.VK_ENTER);
    rob.keyRelease(KeyEvent.VK_ENTER);
    Thread.sleep(1000);
    rob.keyPress(KeyEvent.VK_TAB);
    rob.keyRelease(KeyEvent.VK_TAB);
    Thread.sleep(1000);
    rob.keyPress(KeyEvent.VK_ENTER);
    rob.keyRelease(KeyEvent.VK_ENTER);
    Thread.sleep(1000);
    rob.keyPress(KeyEvent.VK_ESCAPE);
    rob.keyRelease(KeyEvent.VK_ESCAPE);

}

Upvotes: 0

undetected Selenium
undetected Selenium

Reputation: 193108

Microsoft's compatibility View / Mode in Internet Explorer

As per Compatibility View / Mode in Microsoft IE10 and IE11 Compatibility View / Mode was introduced in Internet Explorer 8 to help existing content continue to work with Internet Explorer 7, giving time for developers to updated their content to support newer web standards. In previous versions of Internet Explorer the Compatibility View button would attempt to fix a broken standards-based website, by getting the page to appear like it did in Internet Explorer 7. Today however, many standards-based websites are broken by attempting to appear like they did in Internet Explorer 7.

In earlier version of IE such as IE 10 and older, IE offered the check box Display all websites in Compatibility View option. This option caused problems with todays standard based websites. In IE 11, this option and the Compatibility View button was removed. The Compatibility View add option was kept to allow the user put a website into Compatibility View / Mode on a individual bases. In addition Microsoft kept the check box Display intranet sites in Compatibility View option. Today most intranet websites and web based appliances also meet standards-based web designs and this option in general is less important.

In earlier versions of IE such as IE 10, a Compatibility View button would indicate that a website is in Compatibility View / Mode. When you hover over the Compatibility View button, you will get a Compatibility View popup message. In IE 11 the Compatibility View button is removed.

Steps to disable the Compatibility View / Mode setting in IE 11

Step 1:

  • Open up Internet Explorer (IE 11)
  • Press the Alt key on your keyboard, this will make a menu bar appear
  • Click on the Tools menu tab
  • Select the Compatibility View settings option

Step 2:

  • In IE 11, the Display all websites in Compatibility View option is not available
  • Uncheck the Display intranet sites in Compatibility View option

Note: If you feel that a URL can benefit from using Compatibility View / Mode, you can add it to the Compatibility View box.

Sometimes websites don't look like you expect them to—images might not appear, menus might be out of place, and text could be jumbled together. This might be caused by a compatibility problem between Internet Explorer and the site you're on. Sometimes this can be fixed by adding the site to your Compatibility View list.

As per Fix site display issues with Compatibility View in Internet Explorer 11 to add a site to the Compatibility View list:

  • Open Internet Explorer, select the Tools button , and then select Compatibility View settings.
  • Under Add this website, enter the URL of the site you want to add to the list, and then select Add.

Note: If you add a site to the Compatibility View list and the page looks worse, the problem might not be compatibility and you should remove the site from the list.

Once you turn on Compatibility View, Internet Explorer will automatically show that site in Compatibility View each time you visit. You can turn it off by removing the site from your compatibility list. Not all website display problems are caused by browser incompatibility. Interrupted Internet connections, heavy traffic, or problems with the website can also affect how a page is displayed.

To clear the list of Compatibility View sites:

  • Open Internet Explorer, select the Tools button , and then select Internet options.
  • Under Browsing history, select Delete.
  • In the Delete Browsing History dialog box, select the History check box, and then select Delete.

Conclusion

As you are using IE 11 through Selenium and IEDriverServer you don't need to worry about Compatibility View as this feature have been removed from IE 11.

Reference

You can find a relevant discussion in IE11 fails with “Netscape is not supported please used internet explorer” error when launch by Selenium

Upvotes: 1

Related Questions