-1

When I initialize IE browser using Selenium C#,

 case BrowserType.InternetExplorer:
                     IWebDriver driver = new InternetExplorerDriver("C:\\Program Files\\internet
 explorer\\iexplore.exe");
                     driver.Navigate().GoToUrl("http://www.google.com");
                    //InternetExplorerOptions options2= new InternetExplorerOptions();
                    // options2. = ("C:\\Program Files\\internet explorer\\iexplore.exe");
                     //DriverContext.Driver = new InternetExplorerDriver();
                     //DriverContext.Browser = new Browser(DriverContext.Driver);
                    // DriverContext.Browser.Maximize();
                  break;

I get the following error:

System.NullReferenceException : Object reference not set to an instance of an object. TearDown : System.NullReferenceException : Object reference not set to an instance of an object.

Wyck
  • 10,311
  • 6
  • 39
  • 60
Sara
  • 3
  • 4
  • What is the error? – mjwills Aug 06 '19 at 12:45
  • System.NullReferenceException : Object reference not set to an instance of an object. TearDown : System.NullReferenceException : Object reference not set to an instance of an object. – Sara Aug 06 '19 at 12:46
  • 1
    Possible duplicate of [What is a NullReferenceException, and how do I fix it?](https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – nilsK Aug 06 '19 at 12:48
  • Hi @mjwills,I'm trying to trigger the IE browser and run my code which works fine in Chrome n FIrefox. Below is the bit of code I used: case BrowserType.Firefox: FirefoxOptions options1 = new FirefoxOptions(); options1.BrowserExecutableLocation = ("C:\\Program Files\\Mozilla Firefox\\firefox.exe"); //This is the location where you have installed Firefox on your machine – Sara Aug 06 '19 at 12:49
  • case BrowserType.Firefox: FirefoxOptions options1 = new FirefoxOptions(); options1.BrowserExecutableLocation = ("C:\\Program Files\\Mozilla Firefox\\firefox.exe"); //This is the location where you have installed Firefox on your machine DriverContext.Driver = new FirefoxDriver(); DriverContext.Browser = new Browser(DriverContext.Driver); DriverContext.Browser.Maximize(); break; – Sara Aug 06 '19 at 12:50
  • Is it row `driver.Navigate()...` that throws the exception? – LosManos Aug 06 '19 at 13:41

1 Answers1

1

From the available code the only thing which jumps out to me is that you are specifying the location of IE. I would drop this and allow the webdriver to use the default location. I've never had to specify path with IE. I don't think it's possible for it to be in an alternate location.

J.D. Cain
  • 639
  • 4
  • 16
  • I dropped the path. Still the same error case BrowserType.InternetExplorer: IWebDriver driver = new InternetExplorerDriver(); DriverContext.Driver = new InternetExplorerDriver(); DriverContext.Browser = new Browser(DriverContext.Driver); DriverContext.Browser.Maximize(); break; – Sara Aug 08 '19 at 10:11
  • Can you post the entire class used? – J.D. Cain Aug 08 '19 at 11:21