Everything works besides: links.Remove(linkToClick) since HtmlElementCollection doesn’t have a “Remove” method.
I recently asked a question here: How to have loop move to the next id available rather than doing the same continuously?
and that is what was recommended to me but I have been searching and trying to figure it out for the past two hours and still can’t figure it out.
HtmlElementCollection links = null;
private void button2_Click(object sender, EventArgs e)
{
// This way you only get the links once.
links = webBrowser1.Document.GetElementsByTagName("a");
timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
HtmlElement linkToClick = null;
foreach (HtmlElement link in links)
{
if (link.GetAttribute("id").Contains("user"))
{
linkToClick = link;
break;
}
}
// did I find a link?
if (linkToClick != null)
{
// Remove it from the list so you don't click it again.
links.Remove(linkToClick);
link.InvokeMember("click");
}
}
I would also suggest stopping the timer from within the timer if
linkToClick == null, and why won’t you also FILTER the list in advance?And in timer: