Hello,
I need to automate a web form fill. I have successfully used the VB code I found at http://www.mjtnet.com/forum/viewtopic.php?t=1461
to fill in forms in a series of pages, but for the page I'm working on now, it doesn't appear to work. I also tried the extended version of the code
at http://www.mjtnet.com/forum/viewtopic.php?t=1390, but it doesn't work either. The problem seems to be that the code doesn't find a form
in the page, yet a look at the source shows there is one. The page in question comes from phpMyAdmin. Here's the relevant part of the
source (the form element I'm targeting, named "sql_file", is about halfway down the code):
Run SQL query/queries on database usedpart_wp:
Show this query here again
Or
Location of the text file:
(Max: 51,200KB)
Compression:
Autodetect
None  
"gzipped"
Character set of the file:
armscii8
ascii
big5
binary
cp1250
cp1251
cp1256
cp1257
cp850
cp852
cp866
cp932
dec8
euckr
gb2312
gbk
geostd8
greek
hebrew
hp8
keybcs2
koi8r
koi8u
latin1
latin2
latin5
latin7
macce
macroman
sjis
swe7
tis620
ucs2
ujis
utf8
And here's the code I've been using:
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 WebFormFill(fieldname,fieldvalue,submit)
Dim FormNr
Dim ItemNr
Dim TheForm
if IE.Document.All.Tags("form").Length = 0 then
MsgBox("No form found in page")
else
for FormNr = 0 to IE.Document.Forms.Length - 1
Set TheForm = IE.Document.Forms(FormNr)
for ItemNr = 0 to TheForm.Elements.Length - 1
if TheForm.Elements(ItemNr).Name = fieldname then
TheForm.Elements(ItemNr).Value = fieldvalue
If submit=1 then
TheForm.submit
end if
exit for
end if
next
next
end if
End Sub
'This function extracts text from a specific tag by name and index
'e.g. TABLE,0 (1st Table element) or P,1 (2nd Paragraph element)
'set all to 1 to extract all HTML, 0 for only inside text without HTML
Function ExtractTag(TagName,Num,all)
dim t
set t = IE.document.getElementsbyTagname(Tagname)
if all=1 then
ExtractTag = t.Item(Num).outerHTML
else
ExtractTag = t.Item(Num).innerText
end if
End Function
VBEND
VBRun>CreateIE
VBRun>Navigate,http://%usernm%:%password%@mydomain.com ... ry_force=1
Wait>1
SetFocus>%usernm%_wp |*
Wait>1
VBRun>WebFormFill,sql_file,%wbstsdir%automate\posttebatch\wpstarter-%usernm%.txt,0
Wait>1
Thanks in advance for any suggestions as to how to make this work.
Iain
Web form automation problem
Moderators: JRL, Dorian (MJT support)
Since you know the name of the form and the name of the form element you might want to try a more direct approach. See this post:
http://www.mjtnet.com/forum/viewtopic.php?p=9843#9843
http://www.mjtnet.com/forum/viewtopic.php?p=9843#9843
MJT Net Support
[email protected]
[email protected]