1

I'm trying to fill a WPF WebBrowser page using mshtml. But, I'm not able to find out the id of the button from the html. How can I find the ID? Or is there is any alternative to submit the form?

Code:

mshtml.HTMLDocument doc = (mshtml.HTMLDocument)browser.Document;

try
{     
    ((mshtml.HTMLInputElement)doc.all.item("?????")).click();
}

Html page (Continue is the button text):

<li><a href="/uas/oauth/authenticate?oauth_token=3c708034-081f-4aca-b61c-f6518a1e0f8c&amp;trk=uas-continue" class="btn-primary">Continue</a></li>
4

1 回答 1

1

中的WebBrowser控件与 中的控件WPF不同WinForm

System.Windows.Controls.WebBrowser 控件有一个 Document 属性,该属性获取表示托管 HTML 页面的 Document 对象。

您需要将此 Document 对象转换为 COM 接口IHTMLDocument2,然后访问文档上的 all 属性以获取 HTML 文档中的每个元素。

mshtml.IHTMLDocument2 doc = webBrowser.Document as mshtml.IHTMLDocument2;
doc.all.item("link")).click();

请参考 MSDN 文章: 处理 HTML 元素事件

类似的帖子:从 WebBrowser 访问 DOM

于 2013-05-03T19:47:09.610 回答