Page 1 of 1

C# code to Login

Posted: Tue Sep 22, 2015 11:06 am
by dsingh
Hi Team,

I am new to your tool and i need some help to login a site. I can do that by recording. But I want to do it using my C# code.
I have to do following tasks using ranorax libraries:
1. Seamless/No browser.
2. Login to website.
3. Once login, I want to read the https cookies form the browser control.

Where can I find the sample code to do the same activity.

Thanks
Dev

Re: C# code to Login

Posted: Wed Sep 23, 2015 4:14 am
by pkaraya
Hi,
//Create a webdocument by domain
WebDocument webDocument = "/dom[@domain=yourdomainname"]";
// Execute a javascript code
string allcookies = webDocument.ExecuteScript("return document.cookie;");
string cookieName="thenameofthecookieyouaresearching";
string[] lines = Regex.Split(allcookies, ";");

foreach (string line in lines) {
// Extract value of selected cookie and return value as string.
if (line.StartsWith(cookieName + "=")){
cookieValue = line.Substring(line.IndexOf("=") + 1);
}
}

I hope this help you
Peter