C# 调用并单击div中的按钮
我正在开发一个客户端应用程序,它需要单击网页中的某个按钮。因为页面上有多个按钮具有相同的类&id,所以我需要添加一个额外的约束以确保右按钮被单击 例如,这是需要单击的特定按钮的源代码C# 调用并单击div中的按钮,c#,webbrowser-control,C#,Webbrowser Control,我正在开发一个客户端应用程序,它需要单击网页中的某个按钮。因为页面上有多个按钮具有相同的类&id,所以我需要添加一个额外的约束以确保右按钮被单击 例如,这是需要单击的特定按钮的源代码 <div class="buttondiv" data-id="118"> <button type="button" class="special"></button> </div> <div class="buttondiv" data-id="11
<div class="buttondiv" data-id="118">
<button type="button" class="special"></button>
</div>
<div class="buttondiv" data-id="119">
<button type="button" class="special"></button>
</div>
如何实现这一点有什么建议吗?是否有理由不使用Javascript甚至jQuery执行此操作?此外,使用相同ID的多个控件是无效的。ID在DOM中必须是唯一的。在同一页面上使用多个ID是无效的HTML。如果由于某种原因无法更改ID,则可以基于其他条件(如类名、数据属性、与其他元素的接近程度等)选择元素。。。实现这一点的最佳方法是使用Javascript或jQuery处理Button click事件,然后您的C#代码可以在服务器上获取它。
if ((div id == "118") && (button class == special))
{
element.InvokeMember("click");
}