HtmlElementCollection には「Remove」メソッドがないため、links.Remove(linkToClick) 以外はすべて機能します。
私は最近ここで質問をしました: How to have loop move to the next id available rather than doing the same?
それが私に勧められたものですが、過去2時間検索して理解しようとしてきましたが、まだ理解できません.
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");
}
}