Reputation: 11
I am using visual basic 2008
I want to fill out forms, and I dont want to submit a POST url.
Instead, I need to access directly the DOM object, and somehow click or interact it programmatically.
should I use WebBrowser class ?
Can you show a sample code where text is entered into an input box, and the submit button is clicked ? ex) google.com
Upvotes: 0
Views: 279
Reputation: 941465
Yes, you can use WebBrowser and use its Document property to modify the DOM. This example code runs a google query with the I Feel Lucky button:
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
webBrowser1.Url = new Uri("http://google.com");
webBrowser1.DocumentCompleted += webBrowser1_DocumentCompleted;
}
void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) {
if (webBrowser1.Url.Host.EndsWith("google.com")) {
HtmlDocument doc = webBrowser1.Document;
HtmlElement ask = doc.All["q"];
HtmlElement lucky = doc.All["btnI"];
ask.InnerText = "stackoverflow";
lucky.InvokeMember("click");
}
}
}
Knowing the DOM structure of the web page is essential to make this work. I use Firebug, there are many others.
Upvotes: 1
Reputation: 11592
You could try something like
<input type="text" id="txtSomething" name="txtSomething" onblur="document.forms[0].submit()">
Which will submit the first form on your web page every time the text box loses focus.
Upvotes: 0