Jump to content

IE form loop


Recommended Posts

I'm having some trouble getting this loop to actually fill out the data on an internal login page. I've included my code as well as a screenshot of the HTML. Can someone tell me what I'm doing wrong or what I should try instead?

 

Global $oIE = _IECreate($sURL, 0, 1, 1, 1)
    WinSetState("[ACTIVE]", "", @SW_MAXIMIZE)
    Sleep(5000)
    $colForms = _IEFormGetCollection($oIE) ; get all forms
    For $oForm In $colForms ; loop over form collection
        $oFormElements = _IEFormElementGetCollection($oForm) ; get all elements
        For $oFormElement In $oFormElements ; loop over element collection
            If $oFormElement.name = '_id0:logon:USERNAME' Then _IEFormElementSetValue($oFormElement, $Username, 0)
            If $oFormElement.name = '_id0:logon:PASSWORD' Then _IEFormElementSetValue($oFormElement, $Password, 0)
        Next
        _IEFormSubmit($oForm,10)
    Next

HTML Screenshot:

http://s32.postimg.org/4oscl5swl/Capture.png

Link to comment
Share on other sites

Try:

Global $oIE = _IECreate($sURL, 0, 1, 1, 1)
    WinSetState("[ACTIVE]", "", @SW_MAXIMIZE)
    Sleep(5000)
    $colForms = _IEFormGetCollection($oIE) ; get all forms
    For $oForm In $colForms ; loop over form collection
        $oFormElements = _IEFormElementGetCollection($oForm) ; get all elements
        For $oFormElement In $oFormElements ; loop over element collection
            If $oFormElement.id = '_id0:logon:USERNAME' Then _IEFormElementSetValue($oFormElement, $Username, 0)
            If $oFormElement.id = '_id0:logon:PASSWORD' Then _IEFormElementSetValue($oFormElement, $Password, 0)
        Next
        _IEFormSubmit($oForm, 1)
    Next

Or:

Global $oIE = _IECreate($sURL, 0, 1, 1, 1)
    WinSetState("[ACTIVE]", "", @SW_MAXIMIZE)
    Sleep(5000)
    $oForm = _IEFormGetObjByName($oIE, "_id0")
    $oUserName = _IEGetObjById($oForm, "_id0:logon:USERNAME")
    $oPassword = _IEGetObjById($oForm, "_id0:logon:PASSWORD")
    _IEFormElementSetValue($oUserName, $Username, 0)
    _IEFormElementSetValue($oPassword, $Password, 0)
    _IEFormSubmit($oForm, 1)

 

Link to comment
Share on other sites

Neither of them worked unfortunately (populating or submitting). Its like it isn't even binding to the form. The form submit command does highlight the submit button but it doesn't actually hit it so I'm not sure what is going on.

Link to comment
Share on other sites

Post the console output.

Global $oIE = _IECreate($sURL, 0, 1, 1, 1)
    WinSetState("[ACTIVE]", "", @SW_MAXIMIZE)
    Sleep(5000)
    
    Local $oUserName = $oIE.document.getElementById("_id0:logon:USERNAME")
    If Not IsObj($oUserName) Then Exit ConsoleWrite("Error in $oUserName" & @CRLF)
    
    Local $oPassword = $oIE.document.getElementById("_id0:logon:PASSWORD")
    If Not IsObj($oPassword) Then Exit ConsoleWrite("Error in $oPassword" & @CRLF)
    
    $oUserName.Value = "Username"
    $oPassword.Value = "Passwd"

 

Link to comment
Share on other sites

--> IE.au3 T3.0-2 Warning from function internal function __IEIsObjType, Cannot register internal error handler, cannot trap COM errors (Use _IEErrorHandlerRegister() to register a user error handler)
--> IE.au3 T3.0-2 Warning from function internal function __IEIsObjType, Cannot register internal error handler, cannot trap COM errors (Use _IEErrorHandlerRegister() to register a user error handler)
--> IE.au3 T3.0-2 Warning from function _IELoadWait, Cannot register internal error handler, cannot trap COM errors (Use _IEErrorHandlerRegister() to register a user error handler)
Error in $oUserName

I often see the __IEIsObjType error but more often than not, my IE scripts still work.

Edited by Jewtus
Link to comment
Share on other sites

Lets try this and post the console output.

Global $oIE = _IECreate($sURL, 0, 1, 1, 1)
    WinSetState("[ACTIVE]", "", @SW_MAXIMIZE)
    Sleep(5000)
    
    If Not IsObj($oIE) Then Exit ConsoleWrite("Error in $oIE" & @CRLF)
    
    $oForm = _IEFormGetObjByName($oIE, "_id0")
    If Not IsObj($oIE) Then Exit ConsoleWrite("Error in $oIE" & @CRLF)
    
    $oUserName = _IEFormGetObjByName($oForm, "_id0:logon:USERNAME")
    If Not IsObj($oUserName) Then Exit ConsoleWrite("Error in $oUserName" & @CRLF)
    
    $oPassword = _IEFormGetObjByName($oForm, "_id0:logon:PASSWORD")
    If Not IsObj($oPassword) Then Exit ConsoleWrite("Error in $oPassword" & @CRLF)
    
    
    _IEFormElementSetValue($oUserName, $Username)
    _IEFormElementSetValue($oPassword, $Password)

Have you noticed the errors in the beginning of the script execution?

Link to comment
Share on other sites

This script is actually isolated but just in case I turned off my error handler. The only lines that I don't include below are the Username, Password, and URL

Error:

--> IE.au3 T3.0-2 Warning from function _IEFormGetObjByName, $_IESTATUS_NoMatch
--> IE.au3 T3.0-2 Error from function _IEFormGetObjByName, $_IESTATUS_InvalidDataType
Error in $oUserName

Code:

#include <IE.au3>
Open()
Exit

Func Open()
    Global $oIE = _IECreate($sURL, 0, 1, 1, 1)
    WinSetState("[ACTIVE]", "", @SW_MAXIMIZE)
    Sleep(5000)

    If Not IsObj($oIE) Then Exit ConsoleWrite("Error in $oIE" & @CRLF)

    $oForm = _IEFormGetObjByName($oIE, "_id0")
    If Not IsObj($oIE) Then Exit ConsoleWrite("Error in $oIE" & @CRLF)

    $oUserName = _IEFormGetObjByName($oForm, "_id0:logon:USERNAME")
    If Not IsObj($oUserName) Then Exit ConsoleWrite("Error in $oUserName" & @CRLF)

    $oPassword = _IEFormGetObjByName($oForm, "_id0:logon:PASSWORD")
    If Not IsObj($oPassword) Then Exit ConsoleWrite("Error in $oPassword" & @CRLF)


    _IEFormElementSetValue($oUserName, $Username)
    _IEFormElementSetValue($oPassword, $Password)
EndFunc

 

Link to comment
Share on other sites

hm... try:

#include <IE.au3>
Open()
Exit

Func Open()
    Global $oIE = _IECreate($sURL, 0, 1, 1, 1)
    WinSetState("[ACTIVE]", "", @SW_MAXIMIZE)
    Sleep(5000)

    $oUserName = $oIE.document.GetElementsByName("_id0:logon:USERNAME").Item(0)
    If Not IsObj($oUserName) Then Exit ConsoleWrite("Error in $oUserName" & @CRLF)

    $oPassword = $oIE.document.GetElementsByName("_id0:logon:PASSWORD").Item(0)
    If Not IsObj($oPassword) Then Exit ConsoleWrite("Error in $oPassword" & @CRLF)
    
    $oUserName.Value = $Username
    $oPassword.Value = $Password
EndFunc

I have tested with using the small sample of the html that you have provided, and its working.

Link to comment
Share on other sites

Well this time I only got this console output:

Error in $oUserName

I wish my company had clean naming conventions for their web portals... or at least something semi standard. This same code works on some of the other portals (different input name though).

Link to comment
Share on other sites

I based my try in this sample:

Spoiler
<form id="_id0" method="post" action="/BOE/portal/1512062157/InfoView/logon.faces" enctype="application/x-www-form-urlencoded" onsubmit="return onSubmitLogon();">

            <script type="text/javascript">document.getElementById("_id0").action = "logon.faces";</script><div class="logonComponent">
<div class="logonInstruction">
<div class="logonFirstInstruction">
Enter your user information, and click "Log On".
</div>
<div class="logonSecondInstruction">
If you are unsure of your account information, contact your system administrator.
</div>
</div>

<div class="logonFields logon_table">
<div class="logonRow" id="_id0:logon:CMS:row">
<div class="logonLabel">
<label for="_id0:logon:CMS">System:</label>
</div>
<div class="logonInput">
<input type="text" id="_id0:logon:CMS" name="_id0:logon:CMS" value="SRCTSTBO:6400" />
</div>

</div>
<div class="logonRow" id="_id0:logon:USERNAME:row">
<div class="logonLabel">
<label for="_id0:logon:USERNAME">User Name:</label>
</div>
<div class="logonInput">
<input type="text" id="_id0:logon:USERNAME" name="_id0:logon:USERNAME" />
</div>

</div>
<div class="logonRow" id="_id0:logon:PASSWORD:row">
<div class="logonLabel">
<label for="_id0:logon:PASSWORD">Password:</label>
</div>
<div class="logonInput">
<input type="password" id="_id0:logon:PASSWORD" name="_id0:logon:PASSWORD" />
</div>

</div>
</div>

<div class="logonButton">
<input type="submit" id="_id0:logon:logonButton" value="Log On" class="logonButtonNoHover logon_button_no_hover" onmouseover="this.className = 'logonButtonHover logon_button_hover';" onmouseout="this.className = 'logonButtonNoHover logon_button_no_hover';" />
</div>

</div>


        <input type="hidden" name="com.sun.faces.VIEW" id="com.sun.faces.VIEW" value="_id281:_id282" /><input type="hidden" name="_id0" value="_id0" />
<script type="text/javascript">
<!--
function clearFormHiddenParams__id0(curFormName) {
  var curForm = document.forms[curFormName];
}
//-->
</script>
</form>

 

Again:

#include <IE.au3>
Open()
Exit

Func Open()
    Global $oIE = _IECreate($sURL, 0, 1, 1, 1)
    WinSetState("[ACTIVE]", "", @SW_MAXIMIZE)
    Sleep(5000)
    
    If Not IsObj($oIE) Then Exit ConsoleWrite("Error in $oIE" & @CRLF)
    
    $FormCollection = _IEFormGetCollection($oIE)
    If Not IsObj($FormCollection) Then Exit ConsoleWrite("Error in $FormCollection" & @CRLF)
    
    ConsoleWrite(@CRLF & "------------ FORMS ID ------------" & @CRLF)
    $i = 1
    For $oForm In $FormCollection
        ConsoleWrite("Form number " & $i & " id: " & $oForm.id & @CRLF)
        $i += 1
    Next
    ConsoleWrite(@CRLF & "------------ FORMS ID ------------" & @CRLF & @CRLF)
    
    Local $oForm_id0 = $oIE.document.getElementById("_id0")
    If Not IsObj($oForm_id0) Then Exit ConsoleWrite("Error in $oForm_id0" & @CRLF)
    
    $oForm_id0_TAGs = $oForm_id0.getElementsByTagName("input")
    If Not IsObj($oForm_id0_TAGs) Then Exit ConsoleWrite("Error in $oForm_id0_TAGs" & @CRLF)
    
    ConsoleWrite(@CRLF & "------------ FORM id0 Input TAG ------------" & @CRLF)
    For $oForm_id0_TAG In $oForm_id0_TAGs
        ConsoleWrite("Input ID: " & $oForm_id0_TAG.id & @CRLF)
        ConsoleWrite("Input ID: " & $oForm_id0_TAG.name & @CRLF)
        ConsoleWrite("Input ID: " & $oForm_id0_TAG.type & @CRLF)
    Next
    ConsoleWrite(@CRLF & "------------ FORM id0 Input TAG ------------" & @CRLF)    
EndFunc

 

Link to comment
Share on other sites

------------ FORMS ID ------------
Form number 1 id: 

------------ FORMS ID ------------

Error in $oForm_id0

Looks like its failing to bind to the form...

Link to comment
Share on other sites

Well I stripped out most of the stuff that I thought I'd get in trouble for uploading (information that we use internally) and this is the HTML:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML 
dir=ltr><HEAD><META content="IE=8.0000" http-equiv="X-UA-Compatible">
<TITLE>BI launch pad</TITLE>
<META content="text/html; charset=utf-8" http-equiv=Content-Type><LINK 
rel="SHORTCUT ICON" href="./images/InfoView.ico"><LINK rel=stylesheet 
type=text/css>

<META name=GENERATOR content="MSHTML 8.00.7601.19104"></HEAD>
<BODY>
<STYLE type=text/css>HTML {
    DISPLAY: none
}
</STYLE>

<SCRIPT type=text/javascript>
     if (parent == top) {
         document.documentElement.style.display = 'block'; 
     } else {
         if (true) {
             top.location = parent.location;
         } else {
             // append warning message so that user gets to see it
             var query = parent.location.search;
             query += (query.indexOf("?") < 0) ? "?" : "&";
             query += "warningMessage=";
             // note: it's this verbose since we can't assign parent.location to a variable without IE blowing up
             top.location = parent.location.protocol + '//' + parent.location.host + parent.location.pathname + query;
         }
     }
     </SCRIPT>

<DIV class=logonContainer>
<DIV class=logonBanner></DIV>
<DIV class=logonProductDescription>
<DIV class=logonProductName>BusinessObjects</DIV>
<DIV class=logonSubTitle>launch pad</DIV></DIV>
<SCRIPT>
            var logonSubmitted = false;
            function onSubmitLogon() {
                if (!logonSubmitted) {
                    logonSubmitted = true;
                    return true;
                }
                // stop event to prevent multiple logon
                return false;
            }
        </SCRIPT>

<FORM id=_id0 encType=application/x-www-form-urlencoded 
onsubmit="return onSubmitLogon();" method=post 
action=/BOE/portal/1502102106/InfoView/logon.faces>
<SCRIPT type=text/javascript>document.getElementById("_id0").action = "logon.faces";</SCRIPT>

<DIV class=logonComponent>
<DIV class=logonInstruction>
<DIV class=logonFirstInstruction>Enter your user information, and click "Log 
On". </DIV>
<DIV class=logonSecondInstruction>If you are unsure of your account information, 
contact your system administrator. </DIV></DIV>
<DIV class="logonFields logon_table">
<DIV id=_id0:logon:CMS:row class=logonRow>
    <DIV class=logonInput>
        <LABEL for=_id0:logon:USERNAME>
        User Name:</LABEL> </DIV>
    <DIV class=logonInput>
        <INPUT id=_id0:logon:USERNAME type=text 
name=_id0:logon:USERNAME>
    </DIV>
    </DIV>
<DIV id=_id0:logon:PASSWORD:row class=logonRow>
<DIV class=logonLabel><LABEL for=_id0:logon:PASSWORD>Password:</LABEL> </DIV>
<DIV class=logonInput><INPUT id=_id0:logon:PASSWORD type=password 
name=_id0:logon:PASSWORD> </DIV></DIV>
    <INPUT id=_id0:logon:logonButton class="logonButtonNoHover logon_button_no_hover" onmouseover="this.className = 'logonButtonHover logon_button_hover';" onmouseout="this.className = 'logonButtonNoHover logon_button_no_hover';" value="Log On" type=submit> </DIV>
</DIV><INPUT id=com.sun.faces.VIEW value=_id15244:_id15245 type=hidden 
name=com.sun.faces.VIEW><INPUT value=_id0 type=hidden name=_id0>
<SCRIPT type=text/javascript>
<!--
function clearFormHiddenParams__id0(curFormName) {
  var curForm = document.forms[curFormName];
}
//-->
</SCRIPT>
 </FORM>
<DIV 
style="BACKGROUND: url(../InfoView/common/appService.do?service=skinning&resource=img&img=img.login.banner.logo) no-repeat" 
class=logonBannerLogo></DIV></DIV></BODY></HTML>

When I tried to run that script against that html, I had different output in the console, but it still didn't fill out the form. Here was the console out when I ran it:

------------ FORMS ID ------------
Form number 1 id: _id0

------------ FORMS ID ------------


------------ FORM id0 Input TAG ------------
Input ID: _id0:logon:USERNAME
Input ID: _id0:logon:USERNAME
Input ID: text
Input ID: _id0:logon:PASSWORD
Input ID: _id0:logon:PASSWORD
Input ID: password
Input ID: _id0:logon:logonButton
Input ID: 
Input ID: submit
Input ID: com.sun.faces.VIEW
Input ID: com.sun.faces.VIEW
Input ID: hidden
Input ID: 
Input ID: _id0
Input ID: hidden

------------ FORM id0 Input TAG ------------

 

Edited by Jewtus
Link to comment
Share on other sites

Using just that part of the html it works. But i cant know what you have stripped that is making the difference. Save just this html and try yourself with this code, you dont even need to grab the form.

#include <IE.au3>
Open()
Exit

Func Open()
    Local $oIE = _IEAttach("", "instance", 1) ;open manually the file or change this to get the oIE
    If Not IsObj($oIE) Then Exit ConsoleWrite("Error in $oIE" & @CRLF)

    Local $oUserName = $oIE.document.getElementById("_id0:logon:USERNAME")
    If Not IsObj($oUserName) Then Exit ConsoleWrite("Error in $oUserName" & @CRLF)

    Local $oPassword = $oIE.document.getElementById("_id0:logon:PASSWORD")
    If Not IsObj($oPassword) Then Exit ConsoleWrite("Error in $oPassword" & @CRLF)

    $oUserName.Value = "UserName"
    $oPassword.Value = "Password"
EndFunc

temp1.jpg

But this sample does not contain all the html neither the the java/scripts that its running in the actual site.

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...