Filling some web form programmatically using WebBr

2020-07-18 06:04发布

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.

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

EDIT

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

标签: c# .net wpf web
1条回答
Juvenile、少年°
2楼-- · 2020-07-18 06:20

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();

the namespace mshtml is located in Microsoft.mshtml Assembly.

Just add reference Microsoft.mshtml.

hope this helps

查看更多
登录 后发表回答