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
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