如何以编程方式模拟按钮点击

发布于 2024-08-24 03:32:07 字数 469 浏览 3 评论 0原文

大家好, 我正在开发一个应用程序,用户可以使用 .net 订阅或取消订阅一组邮件列表。我正在使用 webclient 类,如下所示

NameValueCollection formData = new NameValueCollection();
formData.Add("email", txt_emailid.Text);
WebClient webClient = new WebClient();
byte[] responseBytes = webClient.UploadValues(url, "POST", formData);
string response = Encoding.UTF8.GetString(responseBytes);

,其中响应包含另一个按钮(取消订阅)。我要做的是模拟(取消订阅) ) 按钮以编程方式从我的 .net 应用程序中单击。有什么方法可以做到这一点吗?

谢谢&问候 柴图

Hai every one,
I am developing an application where users can subscribe or unsubscribe to a group of mailing list using .net.I am using webclient class as below

NameValueCollection formData = new NameValueCollection();
formData.Add("email", txt_emailid.Text);
WebClient webClient = new WebClient();
byte[] responseBytes = webClient.UploadValues(url, "POST", formData);
string response = Encoding.UTF8.GetString(responseBytes);

where the response contains one more button(unsubscribe).what i have to do is to simulate the (unsubscribe)button click programmaticaly from my .net application.Is there any way to do this?

Thanks& Regards
Chaithu

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小矜持 2024-08-31 03:32:08

这取决于这个按钮的作用。如果它发送 HTTP 请求,您可以再次使用 WebClient 通过发送所有必要的参数来模拟它。

It depends on what this button is doing. If it sends an HTTP request you could once again use WebClient to simulate it by sending all the necessary parameters.

几味少女 2024-08-31 03:32:07

这听起来像是您试图在网页上进行集成测试,或者几乎暗示与测试相同的情况。

您是否查看过 WATIN (http://watin.sourceforge.net/) 单击按钮,如下所示将允许您找到该按钮并轻松单击它。这将在运行代码的系统上创建一个浏览器实例并执行与其关联的操作(从内存中我认为该实例可以在最小化状态下打开)。您还应该检查一下 Selenium。

如果您想通过 WebClient 类来完成此操作,Darin 的说法是正确的。请记住确保在表单数据中传递按钮的 id,否则服务器将不知道单击了哪个按钮。

It sounds like your trying to do a integration test on a web page or almost imply the same situation as a test.

Have you looked at WATIN (http://watin.sourceforge.net/) for clicking the button as this will allow you to find the button and click it easily. This will create an instance of a browser on the system running the code and do the actions associated with it (from memory I think the instance can be opened in a minimised state). You should also check out Selenium as well.

Darin is correct in what he is saying if you want to do it via a WebClient class. Just remember to make sure you pass the button's id in the form data otherwise the server will not know which button has been clicked.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文