Search code examples
c#wpfmshtml

InvokeMember does not work with WPF Webbrowser


So I am having this issue with automating a webpage. Here's some information:

    private bool refreshing = true;
    private mshtml.HTMLDocument bcode;

    private void browser_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e)
    {
        bcode = browser.Document as mshtml.HTMLDocument;

        if (refreshing)
        {
            bcode.getElementById("refreshPage").InvokeMember("click");
        }
    }

I am using mshtml and it is listed as a reference. The error I am getting is:

  'mshtml.IHTMLElement' does not contain a definition for 'InvokeMember' and no 
   extension method 'InvokeMember' accepting a first argument of type 
  'mshtml.IHTMLElement' could be found (are you missing a using directive or
   an assembly reference?)

I built the code of this ANSWER However I can't see why it works for him (supposedly) and not me.

Apologies if a dupe.


Solution

  • Found the solution,

    HTMLDocument doc = (HTMLDocument)wb1.Document;
            IHTMLElement btn = doc.getElementById("refreshPage");
            if (btn !=null)
            {
                btn.click();
            }
    

    Reference of mshtml.