如何在WebBrowser控件内提交表单?表单、控件、如何在、WebBrowser

2023-09-02 21:33:12 作者:佘樂

如何创建与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控件有一个Document物业,它返回一个HtmlDocument.该的HTMLDocument有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.

一旦你使用这些方法来找到这样的表格,你可以使用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");