5

In java it is possible to set an IE version for internet explorer driver by passing Desired Capabilities. That doesn't work in C#.

I would expect it to look something like:

DesiredCapabilities ieCapabilities = null;
ieCapabilities = DesiredCapabilities.InternetExplorer();
ieCapabilities.SetCapability(CapabilityType.Version, "8");

IWebDriver driver = new InternetExplorerDriver(ieCapabilities);

In c# I cannot pass DesiredCapabilities into InternetExplorerDriver() constructor.

Different
  • 81
  • 1
  • 2
  • 5

2 Answers2

9

The DesiredCapabilities are wrapped up into various Options class for the specific driver.

There is a InternetExplorerOptions class, which allows you to specify extra options for launching IE, and one of the methods on this is AddAdditionalCapability which, will allow you to add any capability you wish to request. This means the options contain the capabilities which is then passed down to the driver.

As for your specific question, no it is not possible. This is also not a limitation of Selenium or the IEDriverServer, but IE itself. You cannot, without major hacks, have more than one version of IE on a machine at once. Think about it the other way - whenever you upgrade IE, it uninstalls the previous version.

It is going to launch the IE you have installed currently. Anything else is pure wrong, and again, it's wrong because you simply cannot have more than one version of IE on a Windows machine at once.

The only way around this is to have separate machines or VM's for each version, or invest in an automated cloud testing framework like SauceLabs.

edit

You have also mentioned you wished to use the compatibility mode of IE8 or wondered if that would work when using the IEDriver.

That is something entirely different (pun intended) again.

The compatibility engine in IE is not, a true representation of that browsers engine. Therefore you must think you are running, say, IE9 with IE7 compatibility mode and thus expect IE7 in full - it won't be, even Microsoft say this, and it is to be used for adhoc testing - it is not to be relied on. Therefore, even if you could do this, it would not be a reliable test in even the slightest terms.

The problem is still not a Selenium issue. The IEDriver is going to call whatever IE is installed and at which point, it's down to IE to set up a session that Selenium can connect to.

It's worth mentioning that all the compatibility options you can use with the IEDriver do not affect IE itself, more the creation of the session and how Selenium interacts with it.

At this point, Selenium throws its hands up in the air, there is very little it can do.

With this in mind, Selenium simply cannot force IE to use a certain browser mode. There is no API at all to do this, and thus, it is not easy to do.

The workaround here, is to force IE to view in a compatibility view in the first place. Your options are very limited:

Force IE9 into browser compatibility view

Community
  • 1
  • 1
Arran
  • 24,648
  • 6
  • 68
  • 78
  • Hi Arran, thank you for your answer. I saw options class and have tried the following: options.AddAdditionalCapability(CapabilityType.Version, "8"); which doesn't give me the desired outcome i.e. running selenium test in a specified IE version (for example, IE8) As regards to the limitation of IE that you have mentioned. If you start Internet explorer and press F12, you can choose among different browser modes (IE7, IE8, compatibility view..). I would expect that it should be possible to run internet explorer driver by setting "browser mode" . – Different May 23 '13 at 22:23
  • See my edit, the short version is, still, there is not much you can do - you will need to force IE to view it in a certain mode in the first place, Selenium has absolutely no control over it - again, not a limitation of Selenium. I will also mention again, you will only be able to use whatever IE is installed on the machine at the time. – Arran May 23 '13 at 22:39
  • The only thing that confuses me is that in java, for example, I can set version capability that does nothing: DesiredCapabilities ieCapabilities = null; ieCapabilities = DesiredCapabilities.internetExplorer(); ieCapabilities.setCapability(CapabilityType.BROWSER_NAME, "Internet Explorer"); ieCapabilities.setCapability(CapabilityType.VERSION, "8"); driver_ie = new InternetExplorerDriver(ieCapabilities); – Different May 24 '13 at 07:57
0

To instantiate different versions, you can set the version using capability.setVersion to the required version number. At the same time, while starting the node, you need to add the following parameters in the command line:

browser "browserName=internet explorer,maxInstances=5,platform=WINDOWS, version=8"

For supporting multiple versions at the same node, you can use "-browser" multiple times.

Rizier123
  • 58,877
  • 16
  • 101
  • 156
Atira_Jak
  • 21
  • 3