0

Part of my WPF application has two text boxes for username and password. With a click of a button, the program should log the user into a website. The issue is that GetElementById is throwing up an error:

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

The code in question is this:

    private void webBrowser1_LoadCompleted(object sender, NavigationEventArgs e)
    {
            webBrowser1.Document.GetElementById("AccountBarLogin").InvokeMember("click");
            webBrowser1.Document.GetElementById("QuickLoginEmail").SetAttribute("value", textBox1.Text);
            webBrowser1.Document.GetElementById("QuickLoginPassword").SetAttribute("value", textBox2.Text);
            webBrowser1.Document.GetElementById("QuickLoginSubmit").InvokeMember("click");
    }

I have added a reference to System.Windows.Forms, as well as to MSHTML. What exactly needs to be referenced to prevent the GetElementByID throwing up this error?

Saw this: System.Windows.Forms.HtmlDocument does not contain a definition for GetElementByID but in this case it does not seem to be a typo.

Community
  • 1
  • 1
Nick_R
  • 21
  • 5

1 Answers1

-1

This is not available in the WPF WebBrowser control.

You will need to use the WinForm WebBrowser control and add it to a WindowsFormHosted control.

Add a WindowsFormHosted to your page then in the code behind create the WinForm WebBrowser control.

XAML

xmlns:my="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIn‌​tegration"

Code Behind

System.Windows.Forms.WebBrowser browser = new System.Windows.Forms.WebBrowser();
windowsFormsHost.Child = browser;
Tsukasa
  • 6,342
  • 16
  • 64
  • 96