WebBrowser and clicking the button

M

matko

There is a button on a website that I would like to click, using code.
This could apply to any website and any sort of button, whose name is
known.

As an example:
1) Navigate to www.google.com.
2) Use the following code:

private void MyButton_Click(object sender, EventArgs e)
{
HtmlElementCollection _collection =
webBrowser1.Document.All.GetElementsByName("btnG");

foreach (HtmlElement _elem in _collection)
{
// Do something with the element...
}
}

It so happens - there is only one element with the name "btnG" on
google.com. It is the "Google Search"-button (which performs a submit
action). How do I click it (let's say within the foreach-block or
anywhere else for that matter) or in any way invoke a click-type event
for it?

(The button in question could actually do anything - not necessarily
act as a submit-button)

....and, finally: Am I doing this the "wrong" way (using HtmlElement and
such)? How would you do it?

Thanks for taking the time to read this ;)
 
C

Cor Ligthert [MVP]

Matko,

Forget it, there are so many ways a button can be made an activated on a
webpage, that even if you have the proper code it would fail for most.

Just my thought,

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top