I have been working on a tutorial that I plan to post to the tech database. It still needs some work but here is a Webpage Explorer I created:
;***************************************************************************
;** Webpage Element Explorer
;**
;** Purpose: Discovering form elements on a webpage
;** Inputs: ignorehidden, inputonly
;** Outputs: Highlights each form element using a red solid border
;** and Display attribute information in a Box
;** Reference:
;**
;**
;** Developer: Deana Falk 2013.10.24
;***************************************************************************
#DefineFunction udfIEPageLoadWait( objIE )
; Wait for webpage to load
While !(objIE.readyState == 'complete' || objIE.readyState == 4 )
Timedelay(0.1)
EndWhile
While !(objIE.document.readyState == 'complete' || objIE.document.readyState == 4 )
Timedelay(0.1)
EndWhile
Return 1
#EndFunction
; Modify these values to change how the script operates
ignorehidden = @TRUE ; change to @FALSE to query hidden form elements
inputonly = @FALSE ; change to @TRUE to query only INPUT form elements.
boxcoords = '750,0,1000,200' ; coordinates of the display box.
boxclr = '255,0,0' ; box background color
url = "http://techsupt.winbatch.com/techsupt/sampleform.html"
; Display form element data in a box
title = 'Discovering form elements on a webpage'
BoxesUp(boxcoords, @NORMAL)
BoxDrawRect(1,'0,0,1000,1000',2)
BoxColor(1,boxclr,0)
BoxCaption(1, title)
WindowOnTop(title, 1)
; Initialize MSIE object
oIE = ObjectCreate("InternetExplorer.Application")
oIE.Visible = @TRUE ; Change to @FALSE to hide the process from the user
oIE.Navigate(url)
; Wait for webpage to load
udfIEPageLoadWait( oIE )
;***************************************************************************
; Get Colection of Forms
;***************************************************************************
; Get document object
oDoc = oIE.Document
; Forms Collection
oForms = oDoc.Forms
; OR
; getElementsByTagName Method
;oForms = oDoc.getElementsByTagName("FORM")
formlist = "" ; Initialize variable
If oDoc != 0 ; Check if you have a valid document handle
; Loop through the collection of forms using index
count = oForms.Length
For index = 0 to count-1
oForm = oForms.Item(index)
If ObjectTypeGet(oForm)=="EMPTY" then continue
formlist = formlist:@tab:index:"|":oForm.id:"|":oForm.name
Next
; ALTERNATE WAY: Loop through the collection of forms
;index = 0
;ForEach oForm in oForms
; If ObjectTypeGet(oForm)=="EMPTY" then continue
; formlist = formlist:@tab:index:"|":oForm.id:"|":oForm.name
; index = index+1
;Next
Else
Pause('Notice','Unable to obtain a handle to the document object on this webpage. Check URL.')
EndIf
formlist = StrTrim(formlist) ; remove leading tab
formindex = Int(ItemExtract(1,AskItemlist("Form Index on a webpage", formlist, @tab, @unsorted, @single ),"|"))
If formindex == "" then formindex = 0 ;Confirm user selected form name
oForm = oForms.Item(formindex)
;***************************************************************************
; Get Collection of Elements in the Form
;***************************************************************************
If oForm != 0 ; Check if you have a valid form handle
cElements = oForm.Elements
elementindex = 0
BoxButtonDraw(1, 1, 'Next Element', '250,750,650,900')
ForEach oElement in cElements
; Get element attributes
; Alternatice option: oElement.getAttribute("attributename")
tag = oElement.nodeName ;The value of tagName is the same as that of nodeName.
type = StrUpper(oElement.Type)
id = oElement.Id
name = oElement.Name
value = oElement.Value
; Check if user wants to ignore HIDDEN form elements
If ignorehidden
If StrUpper(type) == 'HIDDEN' then continue
EndIf
; Check if user wants to see non INPUT form elements
If inputonly
If StrUpper(tag) != 'INPUT' then continue
EndIf
; Highlight each element on the form
oElement.style.border = "1mm solid red"
; Set focus on element
If !oElement.disabled
ErrorMode(@off)
oElement.Focus()
ErrorMode(@cancel)
EndIf
; Display results
BoxDrawText(1, "0,0,1000,1000",'Element Index: ' : elementindex : @lf :'Tag: ' : tag : @lf : 'Type: ' : type : @lf :'Id: ' : id : @lf :'Name: ' : name : @lf :'Value: ': value, @TRUE, 0 )
While !BoxButtonStat(1, 1)
TimeDelay(0.5)
Endwhile
; Remove element highlight
oElement.style.border = ""
; Increment element counter
elementindex = elementindex+1
Next
Else
Pause('Notice','Unable to obtain a handle to a form on this webpage. Check URL and formnumber.')
EndIf
:CleanUp
; Quit
oIE.Quit
; Close open COM/OLE handles
oElement
oDoc = 0
oIE = 0
exit