简体   繁体   中英

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.

Found the solution,

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

Reference of mshtml.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM