Friday, 24 January 2014

How to launch the Internet Explorer using Selenium in C#?

It is very simple to start the Internet Explorer browser and start performing the operations on it.
You can first read about how to set up the selenium web driver in visual studio.

You can download the IE driver at  https://code.google.com/p/selenium/downloads/list

Source code (Example)  to automate the Internet Explorer browser is given below.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenQA.Selenium;
using OpenQA.Selenium.IE;
using OpenQA.Selenium.Support.UI;
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

        IWebDriver x = new InternetExplorerDriver(@"F:\selenium\Csharp");
        x.Url = "http://register.rediff.com/commonreg/index.php";
        x.Navigate();
        x.FindElement(By.Id("fullname")).SendKeys ("salunke");

        
        x.Quit();



        }
    }
}

You may run into problems while launching internet explorer like being unable to find elements or being unable to create the new driver instance due to security settings.

InvalidOperationException - due to different protected mode settings


You can follow below steps to fix this issue.

  1. Open Internet Explorer.
  2. Go to Security Tab.
  3. Check Enable Protected Mode for all zones like internet, local intranet, trusted sites, restricted sites.





This is how we can start the Internet Explorer Browser in C# using selenium API.

What do you think on above selenium topic. Please provide your inputs and comments. Thanks

No comments:

Post a Comment

Buy Best Selenium Books

About Me

My photo

Self-motivated software professional