如何在WebBrowser控件内提交表单? [英] How do I submit a form inside a WebBrowser control?
问题描述
如何创建与C#程序提交表单(在Windows应用程序的Web浏览器控件),程序自动?
How can I create a program with C# to submit the form(in the web browser CONTROL in windows Apps)automaticlly ?
推荐答案
在 WebBrowser控件有一个<一个href="http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.document.aspx">Document物业,它返回一个<一个href="http://msdn.microsoft.com/en-us/library/system.windows.forms.htmldocument.aspx">HtmlDocument.该的HTMLDocument有<一个href="http://msdn.microsoft.com/en-us/library/system.windows.forms.htmldocument_members.aspx">several成员你可以用它来遍历和操作DOM。
The WebBrowser control has a Document property, which returns an HtmlDocument. The HtmlDocument has several members you can use to traverse and manipulate the DOM.
一旦你使用这些方法来找到这样的表格,你可以使用<一个href="http://msdn.microsoft.com/en-us/library/system.windows.forms.htmlelement.invokemember.aspx">InvokeMember调用窗体的提交方式。
Once you've used these methods to find the form, you can use InvokeMember to call the form's submit method.
如果您知道该页面有一个表单:
If you know the page has a single form:
foreach (HtmlElement form in webBrowser1.Document.Forms)
form.InvokeMember("submit");
如果您知道形式的ID,你想提交:
If you know the ID of the form you would like to submit:
HtmlElement form = webBrowser1.Document.GetElementById("FormID");
if (form != null)
form.InvokeMember("submit");
这篇关于如何在WebBrowser控件内提交表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!