使用WebBrowser WPF控件以编程方式填充某些Web表单

Saw*_*wan 4 .net c# wpf web

我需要在我的WPF应用程序中的某个网页中预填一些表格(网页在外部网站中),我正在使用WPF WebBrowser控件.

有没有办法做到这一点.

我有一些建议:模拟键盘strocks并使用tab键移动字段,(如何执行此操作).

编辑

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

dkn*_*ack 5

如果你想提交一份表格,你可以查看

     // 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();
Run Code Online (Sandbox Code Playgroud)

命名空间mshtml位于Microsoft.mshtmlAssembly中.

只需添加引用Microsoft.mshtml.

希望这可以帮助

  • 您可以将引用设置为"本地副本"(程序集是bin文件夹的一部分),以确保它每次都可用. (2认同)