title: How to insert string into input field using C# in WPF Webbrowser
body: <p>I have found lots of info on this issue on Stackoverflow, but looks like I'm still missing something. With the Webbrowser I would like to fill in a string into in input field of a certain webpage. By clicking on a button I wish to put some text in the input field.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>using System.Windows.Forms;
  </code></pre>
  
  <p>and the function:</p>
  
  <pre><code>    private void button2_Click(object sender, RoutedEventArgs e)
      {
          HtmlDocument doc = (HtmlDocument)webBrowser1.Document;
          doc.GetElementsByTagName("input")["username"].SetAttribute("Value", "someString");
      }
  </code></pre>
  
  <p>The second button handles then the webBbrowser1.Navigate method. </p>
  
  <p>Then I get this error:</p>
  
  <p><em>{"Unable to cast COM object of type 'mshtml.HTMLDocumentClass' to class type 'System.Windows.Forms.HtmlDocument'. Instances of types that represent COM components cannot be cast to types that do not represent COM components; however they can be cast to interfaces as long as the underlying COM component supports QueryInterface calls for the IID of the interface."}</em></p>
  
  <p>Any ideas? Thanks.</p>