views:

214

answers:

3

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

A: 

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.

Darin Dimitrov
A: 

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.

Mike737
A: 

If you have a button and you want to click it programmatically, you can use method Button.PerformClick

Konstantin Spirin