Getting NullReferenceException

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rahulwagh
    New Member
    • Feb 2013
    • 29

    Getting NullReferenceException

    Hi,
    Below is what I am doing -
    Code:
    private void Example()
    {
      try
      {
       HtmlDocument htmlDocument=webBrowser1.Document;
       HtmlElement newApplication=htmlDocument.GetElementById("menu:StartupPage_NewApplication_NewApplication_Consumer");
    
    //On below line it is throwing exception
    newApplication.InvokeMember("Click");
    }
    Last edited by Rabbit; Mar 12 '13, 10:34 PM. Reason: Please use code tags when posting code.
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Probably newApplication is still null at that point because
    Code:
    GetElementById("menu:StartupPage_NewApplication_NewApplication_Consumer" );
    didn't find what it was looking for. You can put Console.WriteLi nes to see if that is the case.

    Comment

    • rahulwagh
      New Member
      • Feb 2013
      • 29

      #3
      Hi,
      Thanks for youe reply.
      NewApplication is the menu on one webpage. I am opening the webpage using the webbrowser control and after that trying to click the "NewApplication " option.

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Still you are getting the NullReference because GetElementById is not finding anything. So check that your syntax for locating the element is correct and the names match according to the method's standards.

        Comment

        Working...