Jump to content

IE GetobjbyName issue


Go to solution Solved by jdelaney,

Recommended Posts

What I'm trying to accomplish here is to create an autologin. Attachment includes the pic of element insp I got from firefox.

Here's my code:

Func BB()

If WinExists("BB - Windows Internet Explorer", "") Then
WinActivate("BB - Windows Internet Explorer")
winactive("BB - Windows Internet Explorer")
BB2()
Else
Global $oIE = _IECreate ("http://192.168.100.5/Site_SMS/SF_User_Login/User_Login_Frameset.html")
BB2()
EndIf
EndFunc


Func BB2()
Local $oQuery1 = _IEGetObjByName ($oIE, "fldUserName")
Local $oQuery2 = _IEGetObjByName ($oIE, "fldPassword")
_IEFormElementSetValue ($oQuery1, "admin")
_IEFormElementSetValue ($oQuery2,"admin")
_IELoadWait($oIE,0)
$oButton=_IEGetObjById($oIE,"aw4")
_IEAction ($oButton, "click")
exit
EndFunc

The issue here is, it open up the website and thats about it. It doesn't set focus on the input box. Did I do something wrong? Any idea to go beyond this point?

I have tried #AdminRequire as well... same result.

post-76739-0-84564100-1388686676_thumb.j

Edited by asianqueen

Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")
Link to comment
Share on other sites

Do some error handling.  Maybe you are grabbing the object before the page loads it. (you can loop until you find the object)

_IEaction includes an option to 'focus'.  Which generally is a good practice, prior to setting the value.

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

Try these functions

$user = "user"
$oLoginForm = _IEFormGetObjByName($oIE, "nameOfForm");; use the form name for second parameter
$oUser = _IEFormElementGetObjByName($oLoginForm, "fldUserName")
_IEFormElementSetValue($oUser, $user)

edit: changed the login form name, since I do not know what is is..

Edited by allSystemsGo
Link to comment
Share on other sites

Try these functions

$user = "user"
$oLoginForm = _IEFormGetObjByName($oIE, "nameOfForm");; use the form name for second parameter
$oUser = _IEFormElementGetObjByName($oLoginForm, "fldUserName")
_IEFormElementSetValue($oUser, $user)

edit: changed the login form name, since I do not know what is is..

 

Form name = FormLogIn. Tried with no success. Doesn't seem like it's finding any of the objname / id. I give it a sleep (10,000) as well.

Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")
Link to comment
Share on other sites

Maybe this ? check if the button type is "submit" and try this code standalone

$oIE = ObjCreate("InternetExplorer.Application")
$oIE.visible = 1
$oIE.navigate("http://192.168.100.5/Site_SMS/SF_User_Login/User_Login_Frameset.html")
while $oIE.Busy
Sleep(100)
wend
$oInputs = $oIE.document.GetElementsByTagName("input")
For $oInput In $oInputs
    If $oInput.name == "fldUserName" Then $oInput.innertext = "admin"
    If $oInput.name == "fldPassword" Then $oInput.innertext = "admin"  
    If $oInput.type == "submit" Then $oSubmit = $oInput
Next
$oSubmit.Focus()
$oSubmit.Click()
Link to comment
Share on other sites

I did some research on the difference between iframe and frame and it seems like it's an frame.

 

Console didn't display any error. It just end it as soon as I run the script.

will this piece of info help? It's the Insp Info from firefox

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

    <head></head>
    <frameset border="1" framespacing="1" cols="*" rows="52,*">
        <frame id="topFrame" scrolling="No" title="SMS Top Frame" noresize="noresize" name="topFrame" src="User_Login_Top_Page.html">
            #document
                <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                <html xmlns="http://www.w3.org/1999/xhtml">
                    <head></head>
                    <body onselectstart="return false" ondragstart="return false">
                        <div id="divSectPage" class="sms_tp_sect_page">
                            <table width="100%" cellspacing="0" cellpadding="0" border="0">
                                <tbody>
                                    <tr>
                                        <td nowrap="nowrap" width="22%"></td>
                                        <td nowrap="nowrap" width="1%"></td>
                                        <td nowrap="nowrap" width="77%">
                                            <div align="right">
                                                <img id="imgBBTopLogo" width="842" height="49" galleryimg="no" style="visibility:visible" name="imgBBTopLogo" src="../../Site_SMS/images/BBNameLogo.gif"></img>
                                            </div>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </body>
                </html>
        </frame>
        <frameset border="2" frameborder="yes" framespacing="2" cols="177,*" rows="*">
            <frame id="navbarFrame" scrolling="no" src="User_Login_Navbar_Page.html"></frame>
            <frame id="mainFrame" scrolling="no" title="SMS Main Frame" name="mainFrame" src="User_Login_Page.xml">
                #document
                    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                    <html class="aw-all aw-strict aw-vista aw-vista-strict aw-png2">
                        <head></head>
                        <body class="sms_page_style" onload="page_init();" ondragstart="return false">
                            <div id="divPageTitleBar" class="sms_titlebar_style"></div>
                            <div id="divSectHidden" class="sms_ul_sect_hidden" style=""></div>
                            <noscript></noscript>
                            <div id="divSectMain" class="sms_ul_sect_form" style="visibility:visible">
                                <form id="formLogIn" name="formLogIn" method="post" action="cgi-bin/process_login.cgi">
                                    <input id="debugFlag" type="hidden" name="debug" value="0"></input>
                                    <table class="fontstyle01" width="100%" cellspacing="0" cellpadding="0" border="0">
                                        <tbody>
                                            <tr>
                                                <td width="26%"></td>
                                                <td class="fontstyle01" width="44%">
                                                    <div align="left"></div>
                                                </td>
                                                <td width="30%"></td>
                                            </tr>
                                            <tr>
                                                <td></td>
                                                <td>
                                                    <input id="fldUserName" class="fontstyle01" type="text" name="fldUserName" tabindex="1" onkeypress="return keyHandler_Enter(this, event)" value="" size="28" maxlength="64" autocomplete="OFF" style="padding-left:.5em;"></input>
                                                </td>
                                                <td></td>
                                            </tr>
                                            <tr>
                                                <td></td>
                                                <td></td>
                                                <td></td>
                                            </tr>
                                            <tr>
                                                <td></td>
                                                <td>
                                                    <div align="left"></div>
                                                </td>
                                                <td></td>
                                            </tr>
                                            <tr>
                                                <td></td>
                                                <td>
                                                    <input id="fldPassword" class="fontstyle01" type="password" name="fldPassword" onkeypress="return keyHandler_Enter(this, event)" value="" size="28" maxlength="64" tabindex="2" autocomplete="OFF" style="padding-left:.5em;"></input>
                                                    <span id="divCapsOn" style="visibility: hidden; color: #F00; margin-left: 1em;"></span>
                                                </td>
                                                <td></td>
                                            </tr>
                                            <tr>
                                                <td></td>
                                                <td></td>
                                                <td></td>
                                            </tr>
                                            <tr>
                                                <td></td>
                                                <td></td>
                                                <td></td>
                                            </tr>
                                            <tr>
                                                <td></td>
                                                <td>
                                                    <table id="tblButtons" class="fontstyle01" width="239" cellspacing="0" cellpadding="0" border="0">
                                                        <tbody>
                                                            <tr>
                                                                <td width="92">
                                                                    <div id="divBtn01">
                                                                        <span id="aw4" class="aw-system-control aw-item-control aw-ui-button aw-text-expand" onactivate="AW(this,event)" onselectstart="return false" oncontextmenu="return false" title="" hidefocus="true" tabindex="-1" style="width:82px;">
                                                                            <span id="aw4-box" class="aw-item-box"></span>
                                                                        </span>
                                                                    </div>
                                                                </td>
                                                                <td width="31"></td>
                                                                <td width="116">
                                                                    <div id="divBtn02"></div>
                                                                </td>
                                                            </tr>
                                                        </tbody>
                                                    </table>
                                                </td>
                                                <td></td>
                                            </tr>
                                            <tr>
                                                <td></td>
                                                <td></td>
                                                <td></td>
                                            </tr>
                                            <tr>
                                                <td></td>
                                                <td></td>
                                                <td></td>
                                            </tr>
                                            <tr></tr>
                                            <tr>
                                                <td></td>
                                                <td></td>
                                                <td></td>
                                            </tr>
                                            <tr>
                                                <td></td>
                                                <td></td>
                                                <td></td>
                                            </tr>
                                            <tr></tr>
                                        </tbody>
                                    </table>
                                </form>
                            </div>
                            <div id="popupContainer"></div>
                            <div id="popupMask"></div>
                        </body>
                        <script language="JavaScript" type="text/javascript"></script>
                    </html>
            </frame>
        </frameset>
    </frameset>
    <noframes></noframes>

</html>
Edited by asianqueen

Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")
Link to comment
Share on other sites

If you will run the script within Scite, then you will see the error messages output in the console window.

Since there are frames involved, you will need to get a reference to the frame object first. Then you can use this in lieu of $oIE to access the contents of the frame. See the help entries for _IEFrameGetCollection, _IEIsFrameSet, and _IEFrameGetObjByName.

Link to comment
Share on other sites

You'll have to grab the 'frame' object, and then use that as the first param in  _IEFormGetObjByName to grab your inputs.  Do what Danp2 suggested.

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

; *******************************************************
; Example 1 - Display the frameset example, get frame collection,
;                check number of frames, display number of frames or iFrames present
; *******************************************************

#include <IE.au3>

$title = "Schlage bright blue - Windows Internet Explorer"
$Value = "password"

Global $sURL = "http://192.168.50.5/Site_SMS/SF_User_Login/User_Login_Frameset.html"
Global $oIE = _IECreate($sURL, 0, 1, 1, 1)

Local $oForm = _IEFormElementGetCollection($oIE, "formLogIn")
Local $sQuery = _IEFormGetObjByName($oForm, "fldUserName")
_IEFormElementSetValue($sQuery, $Value)

;WinActivate($title)
;winactive($title)
;send("!+{F4}")


Exit
 

with the test code above, I get:

--> Press Ctrl+Alt+F5 to Restart or Ctrl+Break to Stop
--> IE.au3 V2.4-0 Error from function _IEFormElementGetCollection, $_IEStatus_InvalidObjectType
--> IE.au3 V2.4-0 Error from function _IEFormGetObjByName, $_IEStatus_InvalidDataType
--> IE.au3 V2.4-0 Error from function _IEFormElementSetValue, $_IEStatus_InvalidDataType
+>12:58:52 AutoIt3.exe ended.rc:0
>Exit code: 0    Time: 0.819

on console. The exit triggered when it runs the

Local $oForm = _IEFormElementGetCollection($oIE, "formLogIn")
Local $sQuery = _IEFormGetObjByName($oForm, "fldUserName")
_IEFormElementSetValue($sQuery, $Value)

code.

Edited by asianqueen

Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")
Link to comment
Share on other sites

  • Solution

 

It should be

$oForm = _IEFormGetObjByName($oIE, "formLogIn")
$oUser = _IEFormElementGetObjByName($oLoginForm, "fldUserName")
$oPass = _IEFormElementGetObjByName($oLoginForm, "fldPassword")
_IEFormElementSetValue($oUser, "admin")
_IEFormElementSetValue($oPass, "admin")

This won't work, the form is in a frame, you must do what I suggested in Post #11

Try:

$oFrame = _IEFrameGetObjByName($oIE, "mainFrame")
$oForm = _IEFormGetObjByName($oFrame, "formLogIn")
$oUser = _IEFormElementGetObjByName($oLoginForm, "fldUserName")
$oPass = _IEFormElementGetObjByName($oLoginForm, "fldPassword")
_IEFormElementSetValue($oUser, "admin")
_IEFormElementSetValue($oPass, "admin")

note: i just copied and pasted, and did not validate the copied part against your html

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

Bingo!

Global $sURL = "http://192.168.50.5/Site_SMS/SF_User_Login/User_Login_Frameset.html"
Global $oIE = _IECreate($sURL, 0, 1, 1, 1)

$oFrame = _IEFrameGetObjByName($oIE, "mainFrame")
$oForm = _IEFormGetObjByName($oFrame, "formLogIn")
$oUser = _IEFormElementGetObjByName($oForm, "fldUserName")
$oPass = _IEFormElementGetObjByName($oForm, "fldPassword")
_IEFormElementSetValue($oUser, "admin")
_IEFormElementSetValue($oPass, "admin")

this is quite the challenge...

Thank both of you very much... Was about to bust my head open.

Edited by asianqueen

Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")
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...