Board index » Visual Studio » VBScript form posting via IE - any way to vary fields?

VBScript form posting via IE - any way to vary fields?

Visual Studio260
Hello all...



First off, let me say thanks to everyone here for the information I've

found so far on this subject. It's been a huge help!



I'm working on automating some site walk-throughs for one of our

clients. As a part of the process, there are various forms that will

need to be filled out on certain pages. I'm driving the process with

an Access database (we have a few hundred checks we manually perform

every day for our client) so that it's easily modified.



One of the problems that I'm running into, however, is that when

filling in forms via VBScript, I've got to hard-code the references to

the field names in the actual code of my application. For example,

here's the same Yahoo! login script floating around here --



Dim theForm



Set IE = CreateObject("InternetExplorer.Application")

IE.Navigate "mail.yahoo.com"

IE.Visible = TRUE



Do Until IE.Busy = FALSE

WScript.Sleep 10

Loop



Set theForm = IE.document.Forms(1)

ie.document.login_form.login.value="TESTING"

ie.document.login_form.passwd.value="TESTING"

ie.document.login_form.submit()



This would work fine .... if every single site we had to monitor used

"login_form" for the acutal login, and "login" and "passwd" for the

fields on that form. However, that isn't the case.



Hopefully you can see my dilemma -- for every new page, I've got to

modify my script any my database structure to handle a new type of

login form. We're constantly adding and removing pages from our

checks, so I'd really prefer not to do this -- it makes my code

awfully messy. Does anyone know of a way that I can reference

forms/fields in IE via their absolute value as they're found on the

page? For example, form(1), field(1) and field(2)? I've tried a few

variations with no luck, and the documentation I've read doesn't leave

me too hopful.



Thanks in advance!



-Douglas Toombs


-
 

Re:VBScript form posting via IE - any way to vary fields?

Doug Toombs wrote:

Quote
I'm working on automating some site walk-throughs for one of our

clients. As a part of the process, there are various forms that will

need to be filled out on certain pages. I'm driving the process with

an Access database (we have a few hundred checks we manually perform

every day for our client) so that it's easily modified.



One of the problems that I'm running into, however, is that when

filling in forms via VBScript, I've got to hard-code the references to

the field names in the actual code of my application. For example,

here's the same Yahoo! login script floating around here --



Dim theForm



Set IE = CreateObject("InternetExplorer.Application")

IE.Navigate "mail.yahoo.com"">mail.yahoo.com"

IE.Visible = TRUE



Do Until IE.Busy = FALSE

WScript.Sleep 10

Loop



Set theForm = IE.document.Forms(1)

ie.document.login_form.login.value="TESTING"

ie.document.login_form.passwd.value="TESTING"

ie.document.login_form.submit()



This would work fine .... if every single site we had to monitor used

"login_form" for the acutal login, and "login" and "passwd" for the

fields on that form. However, that isn't the case.



Hopefully you can see my dilemma -- for every new page, I've got to

modify my script any my database structure to handle a new type of

login form. We're constantly adding and removing pages from our

checks, so I'd really prefer not to do this -- it makes my code

awfully messy. Does anyone know of a way that I can reference

forms/fields in IE via their absolute value as they're found on the

page? For example, form(1), field(1) and field(2)? I've tried a few

variations with no luck, and the documentation I've read doesn't leave

me too hopful.



The forms collection has a zero-based index, so the first form in a document is

document.forms(0). Each form has an elements collection (also zero-based), so

the first field is elements(0), the second is elements(1), etc.



Here's a routine that will fill the first input=text control in the first form

of a document with a user name, fill the second input=text control with a

password and submit the form.



NeedUser = True

NeedPwd = True

With ie.document.forms(0)

For Each element in .elements

If element.type = "text" Then

If NeedUser Then

element.value = "Username"

NeedUser = False

ElseIf NeedPwd Then

element.value = "Password"

NeedPwd = False

End If

End If

Next

.submit()

End With



--

Steve



It is dangerous to be right when the government is wrong. -Voltaire





-

Re:VBScript form posting via IE - any way to vary fields?

Steve--



Excellent. Exactly what I was looking for. Thanks for the assist!



-Doug







"Steve Fulton" <cerberus40@hotmail.com>wrote in message news:<eIbbK3ynDHA.3316@TK2MSFTNGP11.phx.gbl>...

Quote
The forms collection has a zero-based index, so the first form in a document is

document.forms(0). Each form has an elements collection (also zero-based), so

the first field is elements(0), the second is elements(1), etc.



Here's a routine that will fill the first input=text control in the first form

of a document with a user name, fill the second input=text control with a

password and submit the form.



NeedUser = True

NeedPwd = True

With ie.document.forms(0)

For Each element in .elements

If element.type = "text" Then

If NeedUser Then

element.value = "Username"

NeedUser = False

ElseIf NeedPwd Then

element.value = "Password"

NeedPwd = False

End If

End If

Next

.submit()

End With

-