我想模拟点击c#webbrowser。但我无法成功。
点击此Html代码:
<a aria-label="2" class="rrl" href="javascript:ok();"><span class="ess ch"></span>2</a>
<a aria-label="3" class="rrl" href="javascript:ok();"><span class="ess ch"></span>3</a>
<a aria-label="4" class="rrl" href="javascript:ok();"><span class="ess ch"></span>4</a>
<a aria-label="5" class="rrl" href="javascript:ok();"><span class="ess ch"></span>5</a>
我的错误C#点击代码:
foreach (HtmlElement el in webBrowser1.Document.GetElementsByTagName("a"))
{
if (el.GetAttribute("aria-label") == "4")
{
el.InvokeMember("Click");
}
}
我想点击区号标签
答案 0 :(得分:1)
试试这个
foreach (HtmlElement el in webBrowser1.Document.GetElementsByTagName("a"))
{
if (el.OuterHtml.Contains("</span>4</a>"))
{
el.InvokeMember("click");
break;
}
}