填写一些网络形式的以编程方式使用web浏览器WP​​F控件控件、浏览器、形式、方式

2023-09-03 17:14:09 作者:麻辣小宝贝

我需要$ P $在某些网页在我的WPF应用程序对填充某种形式(该网页是一个外部网站),我使用WPF WebBrowser控件。

I need to pre-fill some form in some web page within my WPF app (The web page is in an external website), i am using WPF WebBrowser control.

是,有一些方法来做到这一点。

Is there are some way to do it.

我有一些建议:模拟键盘strocks,并使用Tab键移动穿过田野,(如何做到这一点)

I have some suggestion: emulating keyboard strocks and use tab key to move through fields, (How to do this).

修改

的期望的形式是如此复杂,元素的名称是动态的,但它们总是以相同的顺序

The desired form is so sophisticated and the names of the elements are dynamic, but they are always in the same order.

推荐答案

如果您要提交你检查这一个形式

if you want to submit a form you check this

     // get the document
     mshtml.IHTMLDocument2 doc = ((mshtml.HTMLDocumentClass)webBrowser1.Document);

     // set a variable
     ((mshtml.IHTMLElement)doc.all.item("q")).setAttribute("value", "my input...");

     // click a button
    ((mshtml.HTMLInputElement)doc.all.item("btnI")).click();

命名空间 MSHTML 位于 Microsoft.mshtml 大会。

只需添加引用Microsoft.mshtml。

Just add reference Microsoft.mshtml.

希望这有助于