简体   繁体   English

WinForms C#或VB中的自动化WebBrowser控件

[英]Automated WebBrowser Control in WinForms C# or VB

使用WebBrowser控件,如何自动将鼠标移至网页上的文本框,键入一些文本,然后以编程方式提交表单?

This really isn't possible, at least not without a bunch of ugly hacks. 这确实是不可能的,至少不是没有一堆丑陋的骇客。

The primary problem is that you'd need some way to be able to identify the textbox control you wish to type into. 主要问题是您需要某种方式来识别您要键入的文本框控件。 That most likely means you need to have designed the HTML form yourself, so that you know what its ID is. 这很可能意味着您需要自己设计HTML表单,以便知道其ID。

If you have a particular website in mind, and you can assume that it's DOM will stay the same for as long as your application needs to continue working (yeah, right), you can try the hacks suggested here: Automating Facebook Login using WebBrowser Control in C# 如果您有一个特定的网站,并且可以假设只要您的应用程序需要继续工作,它的DOM就会保持不变(是的,对),您可以尝试以下建议的技巧: 使用WebBrowser Control自动进行Facebook登录在C#中

But suffice it to say that this smells like a very bad design to me. 但是只要说这对我来说就像一个非常糟糕的设计就可以了。 Automation is tricky to get right as it is, and this particular implementation is trickier than most, considering the dynamic nature of web content. 自动化是很难正确实现的,考虑到Web内容的动态性质,这种特殊实现比大多数实现都更棘手。

If you just need open some url, fill form and submit it I would recommend you to use WatiN . 如果您只需要打开一些URL,请填写表格并提交,我建议您使用WatiN It is used for testing, but should do the work. 它用于测试,但是应该可以完成工作。

如果要将文本框中的值发布到页面,则可以使用“ HttpWebRequest”,如此处所示, 例如,链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM