Click here to Skip to main content
15,888,968 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi!
How can I select a button programmatically after already selecting a button?
Please see below code:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void buttonNavigate_Click(object sender, EventArgs e)
{
string url = "http://www.someurl.com";
webBrowser1.Navigate(url);

while (webBrowser1.ReadyState != WebBrowserReadyState.Complete)
{
Application.DoEvents();
}

HtmlElementCollection elements = webBrowser1.Document.GetElementsByTagName("input");

foreach (HtmlElement element in elements)
{
if (element.GetAttribute("type").Equals("button") && (element.GetAttribute("value").Equals("Click Here")))
{
element.InvokeMember("click");
}


//The code to this point works great. The new page loads using Java I think to provide the link to the new page. The new page loads in the same window which is desirable. The below code does not click a button to load a new page.

Any help would be great!
Nick



HtmlElementCollection elements2 = webBrowser1.Document.GetElementsByTagName("input");

foreach (HtmlElement element2 in elements2)
{
if (element2.GetAttribute("type").Equals("button") && (element2.GetAttribute("value").Equals("Click Here 2")))
{
element2.InvokeMember("click");
}

}
}
}
}
}

I'm wondering why the HtmlElementCollection isn't working on the second instance?
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900