Using Webfillform with document.forms[0].elements[0].value

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
tommytx
Pro Scripter
Posts: 61
Joined: Mon Dec 22, 2003 3:20 am

Using Webfillform with document.forms[0].elements[0].value

Post by tommytx » Thu Nov 24, 2005 7:11 pm

How do I use WebFillForm with document.forms[0].elements[0].value

VBRun>WebFormFill,document.forms[0].elements[0].value,In 1st box Pls.

VBRun>WebFormFill,inbox,Put it in the inbox please.

VBRun>WebFormFill,tom2,This is the third box.

Is there a correct way to fill a form that has no names for each box?

The below statement places "hello dolly" in the form just fine, but how can I do it with script without knowing the acual form name or a form or box without a name.



Thanks
Tom

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Thu Nov 24, 2005 8:15 pm

Pretty much in the same way:

VBSTART
Dim IE

Sub CreateIE
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible=1
End Sub

Sub Navigate(URL)
IE.Navigate URL
do while IE.Busy
loop
End Sub

Sub KillIE
IE.Quit
Set IE = nothing
End Sub

Sub DoIt
IE.Document.forms(0).elements(0).value="hello dolly"
End Sub

VBEND

VBRun>CreateIE
VBRun>Navigate,http://www.somesite.com
VBRun>DoIt
MJT Net Support
[email protected]

tommytx
Pro Scripter
Posts: 61
Joined: Mon Dec 22, 2003 3:20 am

Post by tommytx » Fri Nov 25, 2005 4:05 am

Thanks for your quick response, and I assumed once I knew the basic command I could simply apply it. Below is exactly what I am trying to do, but it does not work can you detect my error in coding that causes it not to work?
Thank you for such a super program, I have been using it off and on, but had not purchased yet do to inability to test the compiler without purchase, so this time when I came back I noted the free test of the compiler and will be purchasing the full complier system in the next few days. Thanks again for your quick response.

When you look at my 3 doit's at the bottom, I am sure you can put me on the right track.

I also love the way you can Navigate direct to a hard disk directory as I am doing., without all the double // and tripple //// stuff. Just a common sense path.

VBSTART
Dim IE

Sub CreateIE
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible=1
End Sub

Sub Navigate(URL)
IE.Navigate URL
do while IE.Busy
loop
End Sub

Sub KillIE
IE.Quit
Set IE = nothing
End Sub

Sub DoIt(x,y,dat)
IE.Document.forms(x).elements(y).value=dat
End Sub

VBEND

VBRun>CreateIE
VBRun>Navigate,C:\_forms_javascript_analyze\test.htm

VBRun>DoIt,0,0,Fill first form
VBRun>DoIt,0,1,Fill another form
VBRun>DoIt,1,0,Fill yet another form

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Fri Nov 25, 2005 8:22 am

Hi,

Not sure why but I get an error using a vb subroutine, but it works with a vb function. This works for me:

VBSTART
Dim IE

Sub CreateIE
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible=1
End Sub

Sub Navigate(URL)
IE.Navigate URL
do while IE.Busy
loop
End Sub

Sub KillIE
IE.Quit
Set IE = nothing
End Sub

Function DoIt(x,y,dat)
IE.Document.forms(x).elements(y).value=dat
End Function

VBEND

VBRun>CreateIE
VBRun>Navigate,f:\html\test.htm
VBEval>DoIt(0,0,"hello"),nul
VBEval>DoIt(0,1,"world"),nul

This populates the first two elements of the first form on the page. Bear in mind that form elements can be hidden and this way of calling the function cares not about that or what their names are or what type of element they are - it simply populates an element by it's index. If the first two elements in the form were hidden the above would appear to the use to do nothing, but would be setting them. This is my test.htm page:












Just two input fields.

If you know the name of the fields you can pass the element name instead of it's index:

VBEval>DoIt(0,"field1","hello"),nul
VBEval>DoIt(0,"field2","world"),nul

If you send a string it uses the name, an integer, it's index. That will work for the form too. So if you know the name of the form:

VBEval>DoIt("myform","field1","hello"),nul
VBEval>DoIt("myform","field2","world"),nul

Isn't Internet Explorer's Document Object Model awesome!!?

This is just scratching at the surface!
MJT Net Support
[email protected]

tommytx
Pro Scripter
Posts: 61
Joined: Mon Dec 22, 2003 3:20 am

Post by tommytx » Fri Nov 25, 2005 8:58 am

Thank you! Thank you! Thank you! That worked fantastic. I was having the same problem as you, it would not work on a subroutine so I am glad you switched to a function. I would have never thought of that. Hey, it would be nice to be able to use this either as a function or sub. However the function will work just fine for me. Maybe you could ear mark this one to see what is causing the error before the next issue of the program. I love this program, so expect to see a compiler order in the next few days.
I tested this thing thoroughly as you can see below. Works fantastic
Thanks again. Hopefully a few others are following along with our discussion and they will also learn some new things.
Also I would never have thought to add the nul on the end.

VBRun>CreateIE
VBRun>Navigate,C:\_forms_javascript_analyze\test.htm
VBEval>DoIt(0,0,"Box 1-1"),nul
VBEval>DoIt(0,1,"Box 2-1"),nul
VBEval>DoIt(0,2,"Box 3-1"),nul

VBEval>DoIt(1,0,"Box 1-2"),nul
VBEval>DoIt(1,1,"Box 2-2"),nul
VBEval>DoIt(1,2,"Box 3-2"),nul

VBEval>DoIt(2,0,"Box 1-3"),nul
VBEval>DoIt(2,1,"Box 2-3"),nul
VBEval>DoIt(2,2,"Box 3-3"),nul

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Fri Nov 25, 2005 9:07 am

Seems to be something to do with the IE interface not liking the values being transformed from MacroScript to VBScript in VBRun. VBEval is safer anyway because it evaluates straight VBScript code. But we'll look into it and see if there is anything obvious going on here.

I added nul because VBEval expects a return variable.

Another, easier, way of creating macros to automate IE is to use WebRecorder: http://www.mjtnet.com/webrecorder.htm
MJT Net Support
[email protected]

tommytx
Pro Scripter
Posts: 61
Joined: Mon Dec 22, 2003 3:20 am

Post by tommytx » Fri Nov 25, 2005 10:19 am

Doesn't webrecorder restrict you to making sure the display is always the same size and etc. With the method I am using, I can shrink the ie screen down to the size of your thumb nail and it still works.
The web recorders I used in the past had been notorious for requiring the screen set the same al the time.
Does your webcorder get around this?
In other words don't it require so many pixels over and so many down.

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Fri Nov 25, 2005 10:23 am

No, WebRecorder does NO GUI work at all. It uses IE's document object model (DOM) but works at an even lower level than VBScript can and is therefore capable of more. With VBScript you will at some point run into site scripting security restrictions which prevent scripts from automating certain objects. WebRecorder uses the IE DOM interface at a lower level that circumvents this.
MJT Net Support
[email protected]

tommytx
Pro Scripter
Posts: 61
Joined: Mon Dec 22, 2003 3:20 am

Post by tommytx » Fri Nov 25, 2005 4:35 pm

Tom Chambers said:
Thank you! Thank you! Thank you! That worked fantastic. (referring to the macro fix above). I was having the same problem as you, it would not work on a subroutine so I am glad you switched to a function. I would have never thought of that. Thanks again for the immediate response.

Tom Chambers said again:
Thank you for the heads up, this has to be the best Macro Recorder since they invented "snuff". For you young folks, that is a tobacco that is chewed. I have used a lot of far more expensive recorders and they just don't hold a candle.
This is definitely not a paid commercial anouncement, and please feel free to use my words in any advertising you would like. Hell I would even be willing to give you an email that you can use with the ad. Don't use my email on file, as if it gets bombarded with inquiries, I might have to back out, but i certainly would respond to a few dozen inquiries. I love you, but not enough to give up my day job just to answer inquires.
Bottom line you have a sold customer for life.

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Fri Nov 25, 2005 6:05 pm

Wow thanks for the wonderful comments! They will get pride of place on our new website :-)
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

nachtegaal9999
Newbie
Posts: 8
Joined: Sun Apr 09, 2006 10:40 pm

How do i do this with the radio button

Post by nachtegaal9999 » Fri Apr 14, 2006 11:46 pm

Hello,

I'have followd your example to fill some text,

My third element is a radio button and i have to tried select it
with value of "true"

but it doesnt work

whats wrong?

OlgaFB
Pro Scripter
Posts: 58
Joined: Mon Nov 01, 2004 3:04 pm
Contact:

Post by OlgaFB » Sat Nov 18, 2006 6:50 pm

support wrote:Seems to be something to do with the IE interface not liking the values being transformed from MacroScript to VBScript in VBRun. VBEval is safer anyway because it evaluates straight VBScript code. But we'll look into it and see if there is anything obvious going on here.

I added nul because VBEval expects a return variable.

Another, easier, way of creating macros to automate IE is to use WebRecorder: http://www.mjtnet.com/webrecorder
I would suggest the reason for the problem with the subroutines: when you call VBEval, then you can transfer all variables the way you want them to be transferred: you are in charge of if the numbers are passed as numbers or as strings. When you call VBRun, the numbers are passed as strings, you have to call CLng in VBScript to transform them to numbers.

So possibly, IE expects to see numbers as function parameters.

Olga.

P.S. I certainly agree, MS is a great program! :)

OlgaFB
Pro Scripter
Posts: 58
Joined: Mon Nov 01, 2004 3:04 pm
Contact:

Re: How do i do this with the radio button

Post by OlgaFB » Sat Nov 18, 2006 6:51 pm

nachtegaal9999 wrote:Hello,

I'have followd your example to fill some text,

My third element is a radio button and i have to tried select it
with value of "true"

but it doesnt work

whats wrong?
Possibly the same problem: if you're calling it passing "true" as string, IE might not like it.

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts