Jump to content

IE object browsing error - randomly happens


Recommended Posts

Hi all,

I've been trying to automate website navigation and I've run into an unusual error that I can't seem to get past. It seems that whenever this function is run, there is a high chance that the function will bomb out and crash the script.

$test = _Interface(True, 1, "User", "Pass")

MsgBox(0, "", $test)

Func _Interface($val, $ftp = 0, $iuser = "", $ipass = "")
    ; $val = True - Set the interface setting to what $ftp is set to (1 or 0)
    ; $val = False  - Check the interface setting
    ; $ftp = 1 - FTP
    ; $ftp = 0 - Cached
    ; $iuser = WebStrat User name
    ; $ipass = WebStrat User password
    Local $to, $fac, $meh, $check
    Local $url = "http://"&@ComputerName&"/hss/authadmin/authadmin.aspx"

    ; If no user name or password was entered, then return from the function
    If $iuser = "" Or $ipass = "" Then
        SetExtended(1)
        Return 1
    EndIf

    $oIE = _IECreate($url, 1, 0)
    $to =  _IELoadWait($oIE, 0, 10000)

    If $to = 0 Or $oIE = 0 Then
        SetExtended(2)
        Return 1
    EndIf

    $oForm =  _IEFormGetObjByName($oIE, "Form1")
    $oUser =  _IEFormElementGetObjByName($oForm, "TextBoxUserId")
    $oPass =  _IEFormElementGetObjByName($oForm, "TextBoxPassword")
    $oLogin = _IEFormElementGetObjByName($oForm, "ButtonLogin")
    _IEFormElementSetValue($oUser, $iuser)
    _IEFormElementSetValue($oPass, $ipass)
    _IEAction($oLogin, "click")
    _IELoadWait($oIE, 0, 10000)

    Sleep(5000)
    If WinExists("Windows Internet Explorer") Then
        ControlClick("Windows Internet Explorer", "", "Button1")
        Sleep(10000)
    ElseIf WinExists("The resource cannot be found.") Then ;In case I can't browse to the website at all
        _IEQuit($oIE)
        SetExtended(2)
        Return 1
    EndIf

    $label = _IEGetObjById($oIE, "LabelMsg")
    $labeltext = _IEPropertyGet($label, "innertext")
    If $labeltext <> 0 Then
        SetExtended(3)
        Return 1
    EndIf

    $fac = _Facility($iuser)

    $oForm =    _IEFormGetObjByName($oIE, "Form1")
    $oSelect =  _IEGetObjByName($oForm, "TabSetupOptions:ListBoxChoices1")
    _IEFormElementOptionselect($oSelect, $fac, 1, "byText")
    _IELoadWait($oIE, 0, 10000)
    $oForm =    _IEFormGetObjByName($oIE, "Form1")
    $oSelect =  _IEGetObjByName($oForm, "TabSetupOptions:ListBoxChoices2")
    _IEFormElementOptionselect($oSelect, $fac, 1, "byText")

    $oForm =    _IEFormGetObjByName($oIE, "Form1")
    If $val = True Then
        _IEFormElementRadioSelect($oForm, "RadioButtonInterfaced", "TabSetupOptions:InterfaceStatus", 1, "byValue")
        _IELoadWait($oIE, 0, 10000)
        $oDoc = _IEDocGetObj($oIE)
        $oArray = $oDoc.getElementsByTagName("input")
        For $element In $oArray
            If String($element.value) = "Cache" And $ftp = 0 Then $element.checked = $val
            If String($element.value) = "FTP" And $ftp = 1 Then $element.checked = $val
        Next
        $oSubmit =  _IEGetObjByName($oIE, "TabSetupOptions:ButtonSaveEWSettings")
        _IEAction($oSubmit, "click")
        _IELoadWait($oIE, 0, 10000)
    ElseIf $val = False Then
        $oDoc = _IEDocGetObj($oIE)
        $oArray = $oDoc.getElementsByTagName("input")
        For $element In $oArray
            ConsoleWrite(String($element.value)&@CRLF)
            If @error Then
                _IEQuit($oIE)
                SetExtended(4)
                Return 1
            EndIf
            If String($element.value) = "Cache" Then
                If $element.checked = True Then $check = "Interface is set to Cache"
            ElseIf String($element.value) = "FTP" Then
                If $element.checked = True Then $check = "Interface is set to FTP"
            EndIf
        Next
    EndIf
    $oForm =    _IEFormGetObjByName($oIE, "Form1")
    $oLogOut =  _IEGetObjByName($oIE, "ButtonLogout")
    _IEAction($oLogOut, "click")
    _IELoadWait($oIE, 0, 10000)
    _IEQuit($oIE)
    If $val = False Then Return $check
EndFunc

Func _Facility($val)
    $oSearch =  _IEGetObjByName($oIE, "TabUsers:ButtonSearch")
    _IEAction($oSearch, "click")
    _IELoadWait($oIE, 0, 10000)

    $oText = _IEGetObjById($oIE, "TabUsers_TextBoxSearchUserID")
    _IEPropertySet($oText, "innertext", $val)
    $oSearch =  _IEGetObjByName($oIE, "TabUsers:ButtonSearch")
    _IEAction($oSearch, "click")
    _IELoadWait($oIE, 0, 10000)

    $oForm =    _IEFormGetObjByName($oIE, "Form1")
    $oSelectCurrentModel = _IEFormElementGetObjByName($oForm, "TabUsers_DropDownListFacility")
    $oOptions = $oSelectCurrentModel.options
    For $oOption In $oOptions
        If $oOption.selected = True Then $sel = $oOption.text
    Next
    $oCancel =  _IEGetObjByName($oIE, "TabUsers:ButtonCancel")
    _IEAction($oCancel, "click")
    _IELoadWait($oIE, 0, 10000)
    Return $sel
EndFunc

More times than not, I receive the following in the console of SciTE:

C:\Documents and Settings\test\My Documents\Scripts\Folder Perms\Version3.au3 (857) : ==> The requested action with this object has failed.:
ConsoleWrite(String($element.value)&@CRLF)
ConsoleWrite(String($element.value^ ERROR
->15:03:05 AutoIT3.exe ended.rc:1
>Exit code: 1    Time: 23.566

All I can tell is that the problem is when I populate the $oArray variable and perform the For loop. I have no idea why this works sometimes and not all the time. Unfortunately, since this is an internal website, I can't provide a working example.

Thanks for the help :unsure:

Link to comment
Share on other sites

Ah. Good idea.

After adding that and rerunning the script a few times, I received a load of error messages like this:

--> COM Error Encountered in Version3.au3
----> $IEComErrorScriptline = 859
----> $IEComErrorNumberHex = 80070005
----> $IEComErrorNumber = -2147024891
----> $IEComErrorWinDescription = Access is denied.
----> $IEComErrorDescription = 
----> $IEComErrorSource = 
----> $IEComErrorHelpFile = 
----> $IEComErrorHelpContext = 
----> $IEComErrorLastDllError = 0

--> COM Error Encountered in Version3.au3
----> $IEComErrorScriptline = 867
----> $IEComErrorNumberHex = 80070005
----> $IEComErrorNumber = -2147024891
----> $IEComErrorWinDescription = Access is denied.
----> $IEComErrorDescription = 
----> $IEComErrorSource = 
----> $IEComErrorHelpFile = 
----> $IEComErrorHelpContext = 
----> $IEComErrorLastDllError = 0

Access is denied? Why would I be getting that?

Edited by buymeapc
Link to comment
Share on other sites

Cross site scripting protections keep you from seeing elements in a FRAME that are from a different site is the most common cause. You would need to get the URL of the frame and open it in its own instance of IE (a tab or separate IE window).

:unsure:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Hmm...that's interesting since it's just the one website calling info from a SQL database. Is there a way to find this different URL since the address bar simply shows the one URL that I'm currently pointing to? Honestly, I'd prefer to retrieve this info directly from the SQL database using a SQL query, but unfortunately I lack the knowledge of SQL commands...

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