Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用WebBrowser WPF控件以编程方式填充某些web表单_C#_.net_Wpf_Web - Fatal编程技术网

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

C# 使用WebBrowser WPF控件以编程方式填充某些web表单,c#,.net,wpf,web,C#,.net,Wpf,Web,我需要在我的WPF应用程序中的某个网页中预先填写一些表单(该网页位于外部网站中),我正在使用WPF WebBrowser控件 有没有办法做到这一点 我有一些建议:模拟键盘敲击并使用tab键在字段中移动(如何做到这一点) 编辑 所需的表单非常复杂,元素名称是动态的,但它们的顺序始终相同。如果要提交表单,请选中此项 // get the document mshtml.IHTMLDocument2 doc = ((mshtml.HTMLDocumentClass)webBrows

我需要在我的WPF应用程序中的某个网页中预先填写一些表单(该网页位于外部网站中),我正在使用WPF WebBrowser控件

有没有办法做到这一点

我有一些建议:模拟键盘敲击并使用tab键在字段中移动(如何做到这一点)

编辑


所需的表单非常复杂,元素名称是动态的,但它们的顺序始终相同。

如果要提交表单,请选中此项

     // 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


希望这有帮助

如果这个外部网站想让你这么做,它会提供API。没有API,但是我不会在非法的地方滥用它!大多数情况下,字段的名称/ID是静态的,很容易发布自动答案。但是如果他们像你说的那样是动态的,那就意味着他们不希望你以编程的方式写这篇文章。不过我会这么做,因为他们没有明确的法律预防措施!它是一个名称空间。只需添加引用Microsoft.mshtml。它是否存在于任何带有.net的计算机上,或者应该单独部署?您可以将引用设置为“本地副本”(程序集是bin文件夹的一部分),以确保其每次都可用。