2012-12-16

How to run selenium webdriver code in IE

In this article we are going to see necessary steps for running selenium web driver code in Internet Explorer. I am using c# code with VS2010.

After adding dll in properties of the project , we have to add the references in the upper section of the class.
using OpenQA.Selenium.IE;

Then we have to initiate the driver object as Internet Explorer Driver. 
private IWebDriver driver  = new InternetExplorerDriver();

Now this driver can be used Just Like as other Firefox or chrome drivers.

We can initiate InternetExplorerDriver with 6 ways(overridden).

1.With no parameter
-InternetExplorerDriver();
2.With a path [need when running remotely]
-InternetExplorerDriver("string")
3. With an Option
-InternetExplorerDriver(options)
4. With a path and an Option
-InternetExplorerDriver("string", options)
5. With a path, an option and Timeout(wait each command)
-InternetExplorerDriver("string",options, cmdTout)
6. With an option, timeout and a specific driver Service.
- InternetExplorerDriver(service, options,cmdTout)

Note : In every case ,
-"string" is the path to the directory containing IEDriverServer.exe
- option  is an object of OpenQA.Selenium.IE.InternetExplorerOptions
- cmdTout is an object of System.TimeSpan
- service is an object of OpenQA.Selenium.DriverService

The Internet Explorer Driver Server link here.
We know , for the safely running without errors 
From IE menu goto tools>Internet Options>Security tab, make sure all your zones are set to the same value



Setting Authentication  via http URL(htaccess) : 

In some cases we may find authentication URL in the starting of the site in JavaScript(like network authentication). We need to pass username and password using URL. By default it is disabled for windows(i use win 7 64). We have add registry key for that. to do that
1. Run Registry edit(in run, regedit.exe)
2. Go to HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_HTTP_USERNAME_PASSWORD_DISABLE]
3. Set iexplore.exe and explorer.exe as 0. if they are not present, add them
"iexplore.exe"=dword:00000000
"explorer.exe"=dword:00000000
 
 So, now running tests in IE will be easier.

.... Thanks...:)... 

No comments:

Post a Comment