Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 14 of 14
  1. #1
    Regular Coder
    Join Date
    Sep 2002
    Location
    California
    Posts
    511
    Thanks
    1
    Thanked 1 Time in 1 Post

    [vb]Need Help with with web form completer script

    Hey,

    Sorry for the kinda cruddy title but ill explain it better. I have been researching how to fill out a web based form using vb for some time now so I could make a progam that logs into a web based account and runs some errands and then signs out, after a long time on google I finally found a site that had exactly what I was looking for so I took it and am trying to adapt it to my needs. Here is the script
    Code:
    Const User = "SomeUser"
    Const Pass = "SomePass"
    
    Private Sub Command1_Click()
      wb1.Navigate2 "http://us.mcafee.com/root/login.asp"
      Do: DoEvents: Loop Until wb1.ReadyState = READYSTATE_COMPLETE
      wb1.Document.Forms("LoginForm").elements("UserID").Value = User
      wb1.Document.Forms("LoginForm").elements("Password").Value = Pass
      wb1.Document.Forms("LoginForm").elements("submit1").Click
    End Sub
    And it corresponds to this web based form




    Code:
    <form action="Login.asp" method="post" id="LoginForm" name="LoginForm">
        <div id="contentMain">
            <input type="hidden" id="SUBMITTED" name="SUBMITTED" value="1" />
            <input type="text" id="UserID" name="UserID" value="" style="width:175px" />
            <input type="password" id="Password" name="Password" value="" style="width:175px" />
            <input type="checkbox" id="RememberMe" name="RememberMe" />
            <input type="submit" id="submit1" name="submit1" value="  Log In  " style="font-size:11px" />
        </div>
    </form>
    It works great for this form but the form im trying to use has alot of that info missing from it like the form name which is required as well as the submit buttons name. Here is the form im trying to have the program log into
    Code:
    <form action="login.php" method="post">
    
    <input type="hidden" name="username">
    <input type="hidden" name="pword">
    <table align="center" class="small" style="padding: 0px 0px 5px 0px;" width="130">
    	<tr>
    		<td align="center"><font color="black">Username:</font></td>
    	</tr>
    	<tr>
    		<td align="center"><input class="login_input" type="text" name="usrname" value=""></td>
    	</tr>
    	<tr>
    
    		<td align="center"><font color="black">Email:</font></td>
    	</tr>
    	<tr>
    		<td align="center"><input class="login_input" type="text" name="uemail" value=""></td>
    	</tr>
    	<tr>
    		<td align="center"><font color="black">Password:</font></td>
    	</tr>
    
    	<tr>
    		<td align="center"><input class="login_input" type="password" name="psword"></td>
    	</tr>
    	<tr>
    		<td align="center" style="padding-top: 5px;"><input class="login_input" type="submit" value="Login" style="width: 50px;"></td>
    	</tr>
    </table>
    </form>
    I am lost as to what I should do to make it log into the above form, if you could help me I would apprecate your time

    *the vb code requires an instance of the webbrowser conrtol named wb1 to work*
    When traveling down the road of life, Try not to drag your face in the gravel.

  • #2
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'd think if the position of the elements is static, to use the collection index: forms(n).elements(n), or loop to compare DHTML or DOM properties, if not.
    *this message will self destruct in n-seconds*

  • #3
    Regular Coder
    Join Date
    Sep 2002
    Location
    California
    Posts
    511
    Thanks
    1
    Thanked 1 Time in 1 Post
    Eh? Im fairly new to vb and ive spent alot of time just figuring out what to search for. Tell me a a bit more about what you mean cuz im a noob
    When traveling down the road of life, Try not to drag your face in the gravel.

  • #4
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try replacing n with a number which corresponds w/ the order in which the elements appear in the collections, such as forms(0).elements(5), or whatever...
    *this message will self destruct in n-seconds*

  • #5
    Regular Coder
    Join Date
    Sep 2002
    Location
    California
    Posts
    511
    Thanks
    1
    Thanked 1 Time in 1 Post
    So what you mean is if I had 5 forms in a web page and each one had 3 elements ,which I assume makes a collection then, if I wanted to fill the 3rd form, 2nd element assuming the forms went in order 1 2 3... then I would have it be forms(3).elements(8)? correct me if im wrong, also what all is considered to be an 'element'?
    When traveling down the road of life, Try not to drag your face in the gravel.

  • #6
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts
    forms is a collection object which is property of document, and elements is a collection object which is a property of a given forms collection, so each form element in a document is part of the forms collection, and can be accessed by name or zero based index, as can each form element of a form, so when you have document.forms(0).elements(0), you are accessing the properties which return specific objects from each collection as such... in this case, the first.
    *this message will self destruct in n-seconds*

  • #7
    Regular Coder
    Join Date
    Sep 2002
    Location
    California
    Posts
    511
    Thanks
    1
    Thanked 1 Time in 1 Post
    so what I post there was only off by one so itd be forms(2).elements(7), im sorry but im a little bit confused, im just learning this. so a form is considered a collection and the tags inside it like the input tages are considered elements? So like in the form I want to fill out there is 6 elements
    When traveling down the road of life, Try not to drag your face in the gravel.

  • #8
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Right, you're working with two collections: forms and elements.
    To get the elements collection, you'd first retrieve a specific form object.
    If this is the first form in the document, it would be document.forms(0), or if the second, document.forms(1), etc.
    Each form.elements element would be accessed in the same manner; for instance, if the button is the fifth, it would be document.forms(n).elements(4)

    Also, just as wb1 represents an object, a reference to the collection may be stored, such as foo = wb1.document.forms(n).elements, and used to set properties from there on, as in foo(0).value = blah
    *this message will self destruct in n-seconds*

  • #9
    Regular Coder
    Join Date
    Sep 2002
    Location
    California
    Posts
    511
    Thanks
    1
    Thanked 1 Time in 1 Post
    Alright, im starting to get it I think, ill play around with it a little today and If I cant get it working ill come back here.
    When traveling down the road of life, Try not to drag your face in the gravel.

  • #10
    Regular Coder
    Join Date
    Sep 2002
    Location
    California
    Posts
    511
    Thanks
    1
    Thanked 1 Time in 1 Post
    Awsome it works, thank you so much for your help with my questions . Now to go off and make my program, im also really gald firefox gets all the form info from the source for me so I dont have to go thru it myself, Go FireFox!
    When traveling down the road of life, Try not to drag your face in the gravel.

  • #11
    Regular Coder
    Join Date
    Sep 2002
    Location
    California
    Posts
    511
    Thanks
    1
    Thanked 1 Time in 1 Post
    I just hit another snag, what can be done if both the number of forms and elements changes so that a certain form/element may be the first form on one occasion and form number 5 on another, also the forms are unnamed but the Elements are like the following element as an example.

    Code:
    <input type="text" name="buy_weapon[11]" value="0" size="3">
    This is a named element from an unnamed form that changes position in the page.
    When traveling down the road of life, Try not to drag your face in the gravel.

  • #12
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try: document.getElementsByName("buy_weapon[11]").item(0)
    *this message will self destruct in n-seconds*

  • #13
    Regular Coder
    Join Date
    Sep 2002
    Location
    California
    Posts
    511
    Thanks
    1
    Thanked 1 Time in 1 Post
    Wow, how do you know this stuff lol, im just starting out with about 2 months of vb skills built up from school but I like a challenge so I thought Id do this becuase ive seen it done by others, thank you for all of your help I dunno what I woulda done without you because asking here was my last resort after a week of googling failed me.
    When traveling down the road of life, Try not to drag your face in the gravel.

  • #14
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Memory's just a side-effect of repetition, er something... BTW, if you plan on experimenting often, then grabbing a local copy of the Platform SDK may save you a lot of time.
    *this message will self destruct in n-seconds*


  •  

    Posting Permissions

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