-4

如果我有一个内置 webbrowser 的 ac# 应用程序,然后我导航到一个网站。我希望我的应用程序找到第一个文本框 IE: email 并用 Xtacy 填充它,然后用密码填充第二个文本框 Password。

在此处输入图像描述

4

2 回答 2

3

您应该找到 Textbox 控件并按如下方式设置值:

HtmlDocument doc = this.webBrowser1.Document;
doc.GetElementById("IE").SetAttribute("Value", "Xtacy");
doc.GetElementById("Password").SetAttribute("Value", "Password");
于 2013-04-22T16:43:37.123 回答
2

You should look at the docs. The WebBrowser class has a Document property. This returns an HtmlDocument which will give you access to the DOM.

Next, you use the GetElementById() to get the input box like below and then set it's value with the SetAttribute method.

HtmlDocument d = this.yourWebBrowser.Document;
d.GetElementById("<id of IE input>").SetAttribute("value", "Xtacy");
d.GetElementById("<id password input>").SetAttribute("value", "Password");
于 2013-04-22T16:38:42.760 回答