Sign in to follow this  
Followers 0
wisem2540

Trying to understand how to interact with IE forms

6 posts in this topic

I have went down this road serveral times.  There are times where I need to use autoit to interact with IE windows and forms, and I never have gotten it to work, and have always either abandonded it or went another route.

I have looked at the IE example form serveral times and to me, it just doesnt quite simulate the complexity of an actual web form. 

I did find a couple more examples and ran them, with no success.

Here is the latest one I tried.

#include <IE.au3>

$oIE = _IECreate("http://www.autoitscript.com")
Local $oForms = _IEFormGetCollection($oIE)
MsgBox(0, "Forms Info", "There are " & @extended & " forms on this page")
For $oForm In $oForms
    MsgBox(0, "Form Info", $oForm.name)
Next

 

This output doesnt make any sense.

So here is my question.  In order to target forms on websites, what exactly do you need?  There are IE Objects, and then there are IE Form Elements (from what I gather)

Can someone explain the differences and perhaps offer up a snippet that would explain it a bit clearer?

thanks

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

The form on your page has no .name attribute, so it returns 0.  if you change the output to .id, you will return a value:

#include <IE.au3>

$oIE = _IECreate("http://www.autoitscript.com")
Local $oForms = _IEFormGetCollection($oIE)
MsgBox(0, "Forms Info", "There are " & @extended & " forms on this page")
For $oForm In $oForms
    MsgBox(0, "Form Info", $oForm.id)
Next

The point of dom crawling is to know where your final destination is, and to know how to find it.  Do you have a dom spy?  Like IE devleoper tools?

Another example to grab data:

#include <IE.au3>

$oIE = _IECreate("http://www.autoitscript.com")
Local $oForms = _IEFormGetCollection($oIE)
;~ MsgBox(0, "Forms Info", "There are " & @extended & " forms on this page")
For $oForm In $oForms
    ConsoleWrite(".getattribute(name): " & $oForm.getattribute("name") & @CRLF & ".name: " & $oForm.name & @CRLF )
    ConsoleWrite(".getattribute(id): " & $oForm.getattribute("id") & @CRLF & "id: " & $oForm.id & @CRLF )
Next

will correctly show nothing for the name, since it doesn't exist

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.

Share this post


Link to post
Share on other sites

Thanks for that. Lets say I had a page with 10 forms on it.....  How would I know which ID belongs to which field?  I obviously could use trial and error.  Just wondering if there is a cleaner way

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

ID's are constant (unless it's a poorly designed web page).  So you script assuming that the input/field IS what you expect, based on the ID.

example: if you are logging into a page, you need to know how to find the loginname/password/logon button...best way would be by ID, generally.  You know what the ID is you are looking for, find that object, and enter data accordingly.

another edit: If you are trying to anticipate fields, that's a different story...good luck :)

last example...looping through all attributes (not just the ones that are visible):

#include <IE.au3>

$oIE = _IECreate("http://www.autoitscript.com")
Local $oForms = _IEFormGetCollection($oIE)
;~ MsgBox(0, "Forms Info", "There are " & @extended & " forms on this page")
For $oForm In $oForms
    ConsoleWrite(".getattribute(name): " & $oForm.getattribute("name") & @CRLF & ".name: " & $oForm.name & @CRLF )
    ConsoleWrite(".getattribute(id): " & $oForm.getattribute("id") & @CRLF & "id: " & $oForm.id & @CRLF )

    For $oAttribute In $oForm.Attributes
        ConsoleWrite( "Name: " & $oAttribute.name & @TAB & "value: " & $oAttribute.value & @CRLF )
    Next
Next
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.

Share this post


Link to post
Share on other sites

I have the IE debug bar installed.  shall i try dom spy instead?

Here is a piece of the sourcecode of the page im trying to edit....

<title>SWAT</title>
 
<script language="JavaScript">
 
function CheckForEmptyField ( inField, inMessage ) {
 
 var isEmpty = ( inField.value == "" );
 
 if ( isEmpty ) {
  alert( inMessage );
 }
 
 return !isEmpty;
}
 
function CheckUserNameField ( ) { 
 return CheckForEmptyField( document.add.user_name, "Specify the login user name." );
}
 
function CheckUserEUIDField ( ) { 
 return CheckForEmptyField( document.add.user_euid, "Specify the RIS User id." );
}
 
function CheckLastNameField ( ) { 
 return CheckForEmptyField( document.add.last_name, "Specify the last name." );
}
 
function CheckFirstNameField ( ) { 
 return CheckForEmptyField( document.add.first_name, "Specify the first name." );
}
 
 

 

So in this case...  are the "document.add.first_name" type names useless?  Would I still have to use something like dom spy to get what I am looking for on these forms?

Share this post


Link to post
Share on other sites

I think I was able to find the names using "inspect element" in Firefox  Now I will test to see if I can send text to them

Share this post


Link to post
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
Sign in to follow this  
Followers 0