CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2010
    Posts
    2

    Trying to login to a webpage that uses javascript with c#

    I am trying to login to http://www.fitchratings.com/ but as it's not asp, but in jscript, I have absolutely no idea how. Would greatly appreciate any pointers

    Username: sccz97test
    Password: testing123

  2. #2
    Join Date
    Jul 2010
    Posts
    15

    Re: Trying to login to a webpage that uses javascript with c#

    Hey, I am doing something similar, and I got my project to work by navigating to the page, and then searching for all of the input fields, adding the correct text, and then programmatically clicking the login button:

    IHTMLDocument2 doc = (IHTMLDocument2)b.Document.DomDocument as IHTMLDocument2;

    //<input size="30" maxlength="32" id="accountpassword" type="password" name="theAccountPW" />
    HTMLInputElement ele = (HTMLInputElement)doc.all.item("theAccountPW", 0);
    ele.value = theAccountPW;

    //<input size="30" autocapitalize="off" autocorrect="off" maxlength="128" id="accountname" type="text" name="theAccountName" />
    ele = (HTMLInputElement)doc.all.item("theAccountName", 0);
    ele.value = theAccountName;

    to enter the user name and password, and:
    //<input border="0" width="0" height="0" type="image" name="1.Continue" />
    b.Document.GetElementById("1.Continue").InvokeMember("click");

    to click the button.

    I originally had done it a different way using the info on this site http://www.dreamincode.net/forums/to...grammatically/ but it stopped working after some time for some reason, and I like my way better anyway.

    edit: theAccountName, and theAccountPW are variables containing strings of the account and password. b is my webBrowser object. I have already navigated to the correct page using the Navigate() method. and the commented html code is from the source code from the website I was logging into programmatically
    Last edited by latetext; August 2nd, 2010 at 04:46 PM.

  3. #3
    Join Date
    Aug 2010
    Posts
    2

    Re: Trying to login to a webpage that uses javascript with c#

    i eventually succumbed and added a webcontrol to the app to login and set the cookies. However, the one problem i have now is that i cant seem to do a refresh without it looking at the cache the page i get never changes. any ideas?

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured