Wednesday 25 January 2012

InternetExplorerDriver() issue by selenium in IE

While running your automation code in selenium using C#.
Then, most probably chances are that you will encounter the exception as Unexpected error launching Internet Explorer. Protected Mode must be set to the same value (enabled or disabled) for all zones. (NoSuchDriver)”. And below is the screen sot for the same.


InvalidOperationException in IE

The cause of this issue is due to different security level and the ability to enable or disable Protected Mode. The error message is trying to tell you that Protected Mode must either be disabled or enabled for all zones because of a limitation in Selenium's InternetExplorerDriver.
To resolve this issue you need to just add 2 extra lines of code.
            var capabilitiesInternet = new OpenQA.Selenium.Remote.DesiredCapabilities();
            capabilitiesInternet.SetCapability("ignoreProtectedModeSettings", true);

The Whole Code would look like this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenQA.Selenium;
using OpenQA.Selenium.IE;
namespace AutomationUsingSelenium
{
    class Program
    {
        static void Main(string[] args)
        {
            var capabilitiesInternet = new OpenQA.Selenium.Remote.DesiredCapabilities();
            capabilitiesInternet.SetCapability("ignoreProtectedModeSettings", true);
            IWebDriver webDriver = new InternetExplorerDriver(capabilitiesInternet);
            webDriver.Navigate().GoToUrl("http://www.google.com");
            IWebElement query = webDriver.FindElement(By.Name("q"));
            query.SendKeys("http://jawedm.blogspot.com");
            Console.WriteLine("Page title is: "+webDriver.Title);
            webDriver.Quit();
            Console.ReadLine();

        }
    }
}


Hope this would be useful for you.
Thanks,
Md. jawed
Keep looking for this space to get different types of automation solutions using Selenium in .Net.

2 comments:

  1. HI,

    I got the error below on this line of the

    IWebDriver webDriver = new InternetExplorerDriver(capabilitiesInternet);

    Error 1 The best overloaded method match for 'OpenQA.Selenium.IE.InternetExplorerDriver.InternetExplorerDriver(string)' has some invalid arguments C:\Users\lope\Documents\Visual Studio 2010\Projects\mySelenium\mySelenium\Program.cs 23 36 mySelenium

    I think IWebDriver webDriver = new InternetExplorerDriver();

    will not run because that will be expecting the path to the IEDriverServer.exe and will throw an error below.

    The IEDriverServer.exe file does not exist in the current directory or in a directory on the PATH environment variable. The driver can be downloaded at http://code.google.com/p/selenium/downloads/list.


    Thanks

    ReplyDelete
  2. It is not working. It gives error: The best overloaded method match for OpenQA.Selenium.IE.InternetExplorerDriver.InternetExplorerDriver(string)' has some invalid arguments

    ReplyDelete