tags:

views:

34

answers:

2

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

A: 

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.

Matt Ellen
+1  A: 

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.

Hans Passant