在WebBrowser中的html代码中查找并单击没有ID的按钮 [英] Finding and clicking a button with no ID within html code in WebBrowser

查看:317
本文介绍了在WebBrowser中的html代码中查找并单击没有ID的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我基本上有一个正在浏览并自动完成某些表格的Web浏览器控件,到目前为止,它一直很容易,但是我已经获得了一个没有标有提交或重置按钮的表格。 ID或名称。 (我必须能够同时单击两者)示例:

I basically have a web-browser control that is going through and automatically completing some forms, it's been a breeze so far, however I've gotten to a form that does not have the "submit " or "reset" button labelled with ID or Name. (I need to be able to click both) Example:

提交按钮

<td align="right" valign="middle" class="LeftSide" style="padding-right: 20; padding-top: 10;"><button class="Search" type="submit" tabindex="7"><b>Search</b></button></td>

重置按钮

<td align="left" valign="middle" class="RightSide" style="padding-left: 20; padding-top: 10;" colspan="2"><button class="Search" type="reset" tabindex="8"><b>Clear</b></button></td>

我如何在HtmlDocument中搜索这些按钮并单击它们?它们嵌套如下:

How would i search the HtmlDocument for these button's and click them? They're nested as the following:

<body><table><form><tr><td><button>'s


推荐答案

,也许?

public void ClickButton(string type) {
    var button = myWebBrowser.Document.GetElementsByTagName("button")
             .Cast<HtmlElement>()
             .FirstOrDefault(m => m.GetAttribute("type") == type);
    if (button != null)
        button.InvokeMember("click"); 
}

用法

ClickButton("reset");
ClickButton("submit");

这篇关于在WebBrowser中的html代码中查找并单击没有ID的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆