WPF Web Browser - How to set values for Input Tags?
-
Tuesday, March 13, 2012 2:17 AM
I am hoping that this is simple, but it's giving me some trouble.
I have a method that will navigate the web browser control to a login page:
private void goNavigateButton_Click(object sender, RoutedEventArgs e) { // Get URI to navigate to Uri uri = new Uri(this.addressTextBox.Text, UriKind.RelativeOrAbsolute); // Only absolute URIs can be navigated to if (!uri.IsAbsoluteUri) { MessageBox.Show("The Address URI must be absolute eg 'http://www.microsoft.com'"); return; } // Navigate to the desired URL by calling the .Navigate method this.myWebBrowser.Navigate(uri); }Once the WebBrowser control has the page, I want to get to the username input tag and put a value into the tag.
Pseudo Code Example : Document.getTagByName("username3").value = "MyName";
Thanks!
All Replies
-
Tuesday, March 13, 2012 2:39 AM
It's not too bad, you need to use mshtml for this.
So first add a reference to Microsoft.mshtml to your project and then something like this:
(untested extract but I think it should work)using mshtml; HTMLDocument dom = (HTMLDocument)Browser.Document; object ie = dom.getElementById(username3); if (ie!=null)
{
if (ie is IHTMLInputElement)
{
((IHTMLInputElement)ie).value = "MyName";
}
}John Fenton, MCC
Wordmasters Direct Mail and Data Processing Services- Marked As Answer by Chris_InformaQuest Tuesday, March 13, 2012 10:43 PM
-
Tuesday, March 13, 2012 10:44 PMThat did the trick, thanks!

