Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium c#: How to launch Internet Explorer driver in a specific version (IE8 for example)

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.

like image 595
Different Avatar asked May 23 '13 15:05

Different


Video Answer


1 Answers

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

like image 52
Arran Avatar answered Oct 03 '22 15:10

Arran