Jump to content

Unusual requirement - filling website input boxes based on label


Recommended Posts

I have a bit of an unusual requirement - I need to complete website input boxes on a number of websites. The content is always the same (name, address etc) however different websites label the input boxes differently, some with id or name containing a meaningful name, other times with general ids or names like input1, input2 etc

The label for the box is almost always meaningful and I was wondering if anyone had a simple way of identifying which input box was with which label. In other words, if I wanted to enter a name, I would need to find the name label and the input box next to the label or below it would need to be completed with the name.

Any help would be appreciated as this one has me beat!

Link to comment
Share on other sites

Well, you just have to work with what you know, and add more cases as you find them.

Maybe to a loop to look for the value of the label, based on an array of similar AKA's (loop until you find one). Generally labels will be within the same parent node as the input, so you can grab the label, and look for .nextsibling (or something like that) until you find the input. Or, create something like an INI file, and store the values for the fields as you grab them, and reference that. Lots of ideas, go for it.

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

I'm happy to loop to find the labels based on the various possible values, however, how would I grab the input box once I had found a label - the code I have for looping through the input boxes is as follows:

$colForms = _IEFormGetCollection($IE) ; get all forms

For $oForm In $colForms ; loop over form collection
$oFormElements = _IEFormElementGetCollection($oForm) ; get all elements
If @error Then ContinueLoop

For $oFormElement In $oFormElements ; loop over element collection
If StringInStr($oFormElement.tagName, "select") Then ; it is a select input
_IEFormElementOptionselect($oFormElement, 1, 1, "byIndex")
_IEFormElementOptionselect($oFormElement, $ringers_array[$i][4], 1, "byText") ; double check if this is a title select (Mr, Mrs etc)
ElseIf StringInStr("input,textarea", $oFormElement.tagName) Then ; it is an input or textarea
If StringInStr("button,hidden,reset,submit,image,password", $oFormElement.type) Then ContinueLoop ; skip to next entry if type is button,hidden,reset,submit
If StringInStr($oFormElement.name, "name") Or StringInStr($oFormElement.name, "author") Then
$value = $ringers_array[$i][5]
EndIf
ElseIf StringInStr($oFormElement.name, "city") Or StringInStr($oFormElement.name, "town") Then
$value = $ringers_array[$i][7]
ElseIf StringInStr($oFormElement.name, "address") Then
$value = $ringers_array[$i][9]
ElseIf StringInStr($oFormElement.name, "time") Or StringInStr($oFormElement.name, "day") Then
$value = "now"
ElseIf StringInStr($oFormElement.name, "no") Or StringInStr($oFormElement.name, "tel") Or StringInStr($oFormElement.name, "phone") Or _
StringInStr($oFormElement.name, "mob") Then
$value = "0" & $ringers_array[$i][1] & $ringers_array[$i][2]
Else
$value = ""
EndIf
Next
Next
Link to comment
Share on other sites

like I said, use .nextsibling (in a loop):

$oSibling = $oFormElement.nextsibling

keep looping till the node = 'input'

Or, you can use:

$oParent = $oFormElement.parentnode

and then find the child of the parent that has node='input'

If you don't understand the above solutions, I suggest you read up on them first...

Google: HTML DOM parentnode

Google: HTML DOM nextsibling

the XML DOM methods are interchangeable with HTML DOM methods

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

I used to work for a biometrics company that had a piece of software that would fill in fields. It had a function that would find "adjacent text". As I remember there was a windows api or ie method that would find elements at certain locations. Get the location of an object and check 10 or 20 pixels in each direction for the next object.

see... elementFromPoint

Edited by LarryDalooza

f_mrcleansmalm_77ce002.jpgAutoIt has helped make me wealthy

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...