Click here to Skip to main content
15,888,104 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I have Automated the task till logging in External site. But after login, i need to perform some tasks like...selecting the menu options...clicking on Download links without any manual efforts..
Please Suggest me some code which detects the menu items,fetch the data from fields if any,clicks the links etc., and does the remaining tasks automatically.(Only Using MVC)

What I have tried:

string appURL = "http://localhost.com";
string strPostData = String.Format("userName={0}&password={1}",
"username", "password");
// Setup the http request.
HttpWebRequest wrWebRequest = WebRequest.Create(appURL) as
HttpWebRequest;
wrWebRequest.Method = "post";
wrWebRequest.ContentLength = strPostData.Length;
wrWebRequest.ContentType = "application/x-www-form-urlencoded";
CookieContainer cookieContainer = new CookieContainer();
wrWebRequest.CookieContainer = cookieContainer;
// Post to the login form.
StreamWriter swRequestWriter = new
StreamWriter(wrWebRequest.GetRequestStream());
swRequestWriter.Write(strPostData);
swRequestWriter.Close();
// Get the response.
HttpWebResponse hwrWebResponse = (HttpWebResponse)wrWebRequest.GetResponse();
// Read the response
StreamReader srResponseReader = new
StreamReader(hwrWebResponse.GetResponseStream());
string strResponseData = srResponseReader.ReadToEnd();
srResponseReader.Close();

Response.Write(strResponseData);
return cookieContainer;
Posted
Updated 21-Feb-20 18:46pm
v2
Comments
F-ES Sitecore 21-Feb-20 5:33am    
You're going to have to know what urls are requested when you click the menus etc (either by analysing the html, or just knowing) and issue requests for those urls in the same way you're doing now.
MadMyche 21-Feb-20 6:56am    
Is there a problem with what you have done already? Is there an error? Does the login work?
Please use the Improve Question widget to let us know what problem you are experiencing
Member 14196861 22-Feb-20 0:35am    
The provided code works fine for Auto login. After login i need to auto click the menu and proceed further. I am stuck on how to get the exact menu item and click automatically.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900