如何以编程方式模拟按钮点击
大家好, 我正在开发一个应用程序,用户可以使用 .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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这取决于这个按钮的作用。如果它发送 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.
这听起来像是您试图在网页上进行集成测试,或者几乎暗示与测试相同的情况。
您是否查看过 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.