如何在C#(webBrowser)中单击具有相同类名的许多按钮中的第二个。
<li class="uJiz5"><button class="g56EM _7_FaD"> 1.Button <span class="MICM7 reportSpriteChevron"></span></button></li>
<li class="uJiz5"><button class="g56EM _7_FaD"> 2.Button <span class="MICM7 reportSpriteChevron"></span></button></li>
<li class="uJiz5"><button class="g56EM _7_FaD"> 3.Button <span class="MICM7 reportSpriteChevron"></span></button></li>
C#代码(只需单击第一个按钮):
foreach(HtmlElement btn in webBrowser1.Document.GetElementsByTagName("button"))
{
if (btn.GetAttribute("className") == "g56EM _7_FaD")
{
btn.InvokeMember("Click");
break;
}
}