#include-once #include "WinAPIError.au3" #include "FileConstants.au3" ; #INDEX# ======================================================================================================================= ; Title .........: Internet Explorer Automation UDF Library for AutoIt3 ; AutoIt Version : 3.3.9++ ; Language ......: English ; Description ...: A collection of functions for creating, attaching to, reading from and manipulating Internet Explorer. ; Author(s) .....: DaleHohm, big_daddy ; Dll ...........: user32.dll, ole32.dll, oleacc.dll ; =============================================================================================================================== #region Header #cs Title: Internet Explorer Automation UDF Library for AutoIt3 Filename: IE.au3 Description: A collection of functions for creating, attaching to, reading from and manipulating Internet Explorer Author: DaleHohm Version: T3.0-0 Last Update: 9/3/12 Requirements: AutoIt3 3.3.9 or higher Update History: =================================================== T3.0-0 9/3/12 Fixes - Removed __IEErrorHandlerREgister() and all internal calls to it. Unneeded as COM errors are no longer fatal - Removed code depricated in V2 - Fixed _IELoadWait check for unrecoverable COM errors - Removed Vcard support from _IEPropertyGet (IE removed support in IE7) - Code cleanup with #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 New Features - Added "scrollIntoView" to _IEAction Enhancements - Added check in __IEComErrorUnrecoverable for COM error -2147023179, "The interface is unknown." - Added "Trap COM error, report and return" to functions that perform blind method calls (those without return values) =================================================== #ce #endregion Header ; #VARIABLES# =================================================================================================================== #region Global Variables Global $__IELoadWaitTimeout = 300000 ; 5 Minutes Global $__IEAU3Debug = False Global $_IEErrorNotify = True Global $o__IEErrorHandler, $s__IEUserErrorHandler Global _; Com Error Handler Status Strings $IEComErrorNumber, _ $IEComErrorNumberHex, _ $IEComErrorDescription, _ $IEComErrorScriptline, _ $IEComErrorWinDescription, _ $IEComErrorSource, _ $IEComErrorHelpFile, _ $IEComErrorHelpContext, _ $IEComErrorLastDllError, _ $IEComErrorComObj, _ $IEComErrorOutput #endregion Global Variables ; =============================================================================================================================== ; #CONSTANTS# =================================================================================================================== #region Global Constants Global Const $IEAU3VersionInfo[6] = ["T", 3, 0, 0, "20120903", "T3.0-0"] Global Const $LSFW_LOCK = 1, $LSFW_UNLOCK = 2 ; ; Enums ; Global Enum _; Error Status Types $_IEStatus_Success = 0, _ $_IEStatus_GeneralError, _ $_IEStatus_ComError, _ $_IEStatus_InvalidDataType, _ $_IEStatus_InvalidObjectType, _ $_IEStatus_InvalidValue, _ $_IEStatus_LoadWaitTimeout, _ $_IEStatus_NoMatch, _ $_IEStatus_AccessIsDenied, _ $_IEStatus_ClientDisconnected Global Enum Step * 2 _; NotificationLevel $_IENotifyLevel_None = 0, _ $_IENotifyNotifyLevel_Warning = 1, _ $_IENotifyNotifyLevel_Error, _ $_IENotifyNotifyLevel_ComError Global Enum Step * 2 _; NotificationMethod $_IENotifyMethod_Silent = 0, _ $_IENotifyMethod_Console = 1, _ $_IENotifyMethod_ToolTip, _ $_IENotifyMethod_MsgBox #endregion Global Constants ; =============================================================================================================================== ; #CURRENT# ===================================================================================================================== ;_IECreate ;_IECreateEmbedded ;_IENavigate ;_IEAttach ;_IELoadWait ;_IELoadWaitTimeout ; ;_IEIsFrameSet ;_IEFrameGetCollection ;_IEFrameGetObjByName ; ;_IELinkClickByText ;_IELinkClickByIndex ;_IELinkGetCollection ; ;_IEImgClick ;_IEImgGetCollection ; ;_IEFormGetCollection ;_IEFormGetObjByName ;_IEFormElementGetCollection ;_IEFormElementGetObjByName ;_IEFormElementGetValue ;_IEFormElementSetValue ;_IEFormElementOptionSelect ;_IEFormElementCheckBoxSelect ;_IEFormElementRadioSelect ;_IEFormImageClick ;_IEFormSubmit ;_IEFormReset ; ;_IETableGetCollection ;_IETableWriteToArray ; ;_IEBodyReadHTML ;_IEBodyReadText ;_IEBodyWriteHTML ;_IEDocReadHTML ;_IEDocWriteHTML ;_IEDocInsertText ;_IEDocInsertHTML ;_IEHeadInsertEventScript ; ;_IEDocGetObj ;_IETagNameGetCollection ;_IETagNameAllGetCollection ;_IEGetObjByName ;_IEGetObjById ;_IEAction ;_IEPropertyGet ;_IEPropertySet ;_IEErrorNotify ;_IEQuit ; ;_IE_Introduction ;_IE_Example ;_IE_VersionInfo ; =============================================================================================================================== ; #INTERNAL_USE_ONLY# =========================================================================================================== ;__IELockSetForegroundWindow ;__IEControlGetObjFromHWND ;__IERegisterWindowMessage ;__IESendMessageTimeout ;__IEIsObjType ;__IEErrorNotify ;__IEInternalErrorHandler ;__IEComErrorUnrecoverable ; ;__IENavigate ;__IEStringToBstr ;__IEBstrToString ;__IECreateNewIE ;__IETempFile ; =============================================================================================================================== #region Core functions ; #FUNCTION# ==================================================================================================================== ; Name...........: _IECreate ; Description ...: Create an Internet Explorer Browser Window ; Parameters ....: $s_Url - Optional: specifies the Url to navigate to upon creation ; $f_tryAttach - Optional: specifies whether to try to attach to an existing window ; 0 = (Default) do not try to attach ; 1 = Try to attach to an existing window ; $f_visible - Optional: specifies whether the browser window will be visible ; 0 = Browser Window is hidden ; 1 = (Default) Browser Window is visible ; $f_wait - Optional: specifies whether to wait for page to load before returning ; 0 = Return immediately, not waiting for page to load ; 1 = (Default) Wait for page load to complete before returning ; $f_takeFocus - Optional: specifies whether to bring the attached window to focus ; 0 = Do Not Bring window into focus ; 1 = (Default) bring window into focus ; Return values .: On Success - Returns an object variable pointing to an InternetExplorer.Application object ; On Failure - Returns 0 and sets @error ; @error - 0 ($_IEStatus_Success) = No Error ; - 1 ($_IEStatus_GeneralError) = General Error ; - 3 ($_IEStatus_InvalidDataType) = Invalid Data Type ; - 4 ($_IEStatus_InvalidObjectType) = Invalid Object Type ; - 6 ($_IEStatus_LoadWaitTimeout) = Load Wait Timeout ; - 8 ($_IEStatus_AccessIsDenied) = Access Is Denied ; - 9 ($_IEStatus_ClientDisconnected) = Client Disconnected ; @extended - Set to true (1) or false (0) depending on the success of $f_tryAttach ; Author ........: Dale Hohm ; =============================================================================================================================== Func _IECreate($s_Url = "about:blank", $f_tryAttach = 0, $f_visible = 1, $f_wait = 1, $f_takeFocus = 1) If Not $f_visible Then $f_takeFocus = 0 ; Force takeFocus to 0 for hidden window If $f_tryAttach Then Local $oResult = _IEAttach($s_Url, "url") If IsObj($oResult) Then If $f_takeFocus Then WinActivate(HWnd($oResult.hWnd)) Return SetError($_IEStatus_Success, 1, $oResult) EndIf EndIf Local $f_mustUnlock = 0 If Not $f_visible And __IELockSetForegroundWindow($LSFW_LOCK) Then $f_mustUnlock = 1 Local $o_object = ObjCreate("InternetExplorer.Application") If Not IsObj($o_object) Then __IEErrorNotify("Error", "_IECreate", "", "Browser Object Creation Failed") Return SetError($_IEStatus_GeneralError, 0, 0) EndIf $o_object.visible = $f_visible ; If the unlock doesn't work we may have created an unwanted modal window If $f_mustUnlock And Not __IELockSetForegroundWindow($LSFW_UNLOCK) Then __IEErrorNotify("Warning", "_IECreate", "", "Foreground Window Unlock Failed!") _IENavigate($o_object, $s_Url, $f_wait) ; Store @error after _IENavigate() so that it can be returned. Local $iError = @error ; IE9 sets focus to the URL bar when an about: URI is displayed (such as about:blank). This can cause ; _IEAction(..., "focus") to work incorrectly. It will give focus to the element (as shown by the elements's ; appearance changing but) the input caret will not move. The work-around for this "helpful" behavior is ; to explicitly give focus to the document. We should only do this for about: URIs and on successful ; navigate. If Not $iError And StringLeft($s_Url, 6) = "about:" Then Local $oDocument = $o_object.document _IEAction($oDocument, "focus") EndIf Return SetError($iError, 0, $o_object) EndFunc ;==>_IECreate ; #FUNCTION# ==================================================================================================================== ; Name...........: _IECreateEmbedded ; Description ...: Create a Webbrowser object suitable for embedding in an AutoIt GUI with GUICtrlCreateObj(). ; Parameters ....: None ; Return values .: On Success - Returns a Webbrowser object reference ; On Failure - Returns 0 and sets @error ; @error - 0 ($_IEStatus_Success) = No Error ; - 1 ($_IEStatus_GeneralError) = General Error ; Author ........: Dale Hohm ; =============================================================================================================================== Func _IECreateEmbedded() Local $o_object = ObjCreate("Shell.Explorer.2") If Not IsObj($o_object) Then __IEErrorNotify("Error", "_IECreateEmbedded", "", "WebBrowser Object Creation Failed") Return SetError($_IEStatus_GeneralError, 0, 0) EndIf ; Return SetError($_IEStatus_Success, 0, $o_object) EndFunc ;==>_IECreateEmbedded ; #FUNCTION# ==================================================================================================================== ; Name...........: _IENavigate ; Description ...: Directs an existing browser window to navigate to the specified URL ; Parameters ....: $o_object - Object variable of an InternetExplorer.Application, Window or Frame object ; $s_Url - URL to navigate to (e.g. "http://www.autoitscript.com") ; $f_wait - Optional: specifies whether to wait for page to load before returning ; 0 = Return immediately, not waiting for page to load ; 1 = (Default) Wait for page load to complete before returning ; Return values .: On Success - Returns -1 ; On Failure - Returns 0 and sets @error ; @error - 0 ($_IEStatus_Success) = No Error ; - 1 ($_IEStatus_GeneralError) = General Error ; - 3 ($_IEStatus_InvalidDataType) = Invalid Data Type ; - 4 ($_IEStatus_InvalidObjectType) = Invalid Object Type ; - 6 ($_IEStatus_LoadWaitTimeout) = Load Wait Timeout ; - 8 ($_IEStatus_AccessIsDenied) = Access Is Denied ; - 9 ($_IEStatus_ClientDisconnected) = Client Disconnected ; @extended - Contains invalid parameter number ; Author ........: Dale Hohm ; =============================================================================================================================== Func _IENavigate(ByRef $o_object, $s_Url, $f_wait = 1) If Not IsObj($o_object) Then __IEErrorNotify("Error", "_IENavigate", "$_IEStatus_InvalidDataType") Return SetError($_IEStatus_InvalidDataType, 1, 0) EndIf ; If Not __IEIsObjType($o_object, "documentContainer") Then __IEErrorNotify("Error", "_IENavigate", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf ; $o_object.navigate($s_Url) If @error Then ; Trap COM error, report and return Local $s_error = @error, $s_function_name = "_IENavigate" __IEErrorNotify("Error", $s_function_name, "$_IEStatus_COMError", $s_error) Return SetError($_IEStatus_ComError, $s_error, 0) EndIf If $f_wait Then _IELoadWait($o_object) Return SetError(@error, 0, -1) EndIf Return SetError($_IEStatus_Success, 0, -1) EndFunc ;==>_IENavigate ; #FUNCTION# ==================================================================================================================== ; Name...........: _IEAttach ; Description ...: Attach to the first existing instance of Internet Explorer where the ; search string sub-string matches based on the selected mode. ; Parameters ....: $s_string - String to search for (for "embedded" or "dialogbox", use Title sub-string or HWND of window) ; $s_mode - Optional: specifies search mode ; Title = (Default) browser title ; URL = url of the current page ; Text = text from the body of the current page ; HTML = html from the body of the current page ; HWND = hwnd of the browser window ; Embedded = title sub-string or hwnd of the window embedding the control ; DialogBox = title sub-string or hwnd of modal/modeless dialogbox ; $i_instance - Optional: specifies the 1-based instance when multiple windows match the criteria. ; For Embedded, DialogBox and HWND it specifies the embedded browser occurance within ; the matching window ; Return values .: On Success - Returns an object variable pointing to the IE Window Object ; On Failure - Returns 0 and sets @error ; @error - 0 ($_IEStatus_Success) = No Error ; - 5 ($_IEStatus_InvalidValue) = Invalid Value ; - 7 ($_IEStatus_NoMatch) = No Match ; @extended - Contains invalid parameter number ; Author ........: Dale Hohm ; =============================================================================================================================== Func _IEAttach($s_string, $s_mode = "Title", $i_instance = 1) $s_mode = StringLower($s_mode) $i_instance = Int($i_instance) If $i_instance < 1 Then __IEErrorNotify("Error", "_IEAttach", "$_IEStatus_InvalidValue", "$i_instance < 1") Return SetError($_IEStatus_InvalidValue, 3, 0) EndIf If $s_mode = "embedded" Or $s_mode = "dialogbox" Then Local $iWinTitleMatchMode = Opt("WinTitleMatchMode", 2) If $s_mode = "dialogbox" And $i_instance > 1 Then If IsHWnd($s_string) Then $i_instance = 1 __IEErrorNotify("Warning", "_IEAttach", "$_IEStatus_GeneralError", "$i_instance > 1 invalid with HWnd and DialogBox. Setting to 1.") Else Local $a_winlist = WinList($s_string, "") If $i_instance <= $a_winlist[0][0] Then $s_string = $a_winlist[$i_instance][1] $i_instance = 1 Else __IEErrorNotify("Warning", "_IEAttach", "$_IEStatus_NoMatch") Opt("WinTitleMatchMode", $iWinTitleMatchMode) Return SetError($_IEStatus_NoMatch, 1, 0) EndIf EndIf EndIf Local $h_control = ControlGetHandle($s_string, "", "[CLASS:Internet Explorer_Server; INSTANCE:" & $i_instance & "]") Local $oResult = __IEControlGetObjFromHWND($h_control) Opt("WinTitleMatchMode", $iWinTitleMatchMode) If IsObj($oResult) Then Return SetError($_IEStatus_Success, 0, $oResult) Else __IEErrorNotify("Warning", "_IEAttach", "$_IEStatus_NoMatch") Return SetError($_IEStatus_NoMatch, 1, 0) EndIf EndIf Local $o_Shell = ObjCreate("Shell.Application") Local $o_ShellWindows = $o_Shell.Windows(); collection of all ShellWindows (IE and File Explorer) Local $i_tmp = 1 Local $f_NotifyStatus, $f_isBrowser, $s_tmp For $o_window In $o_ShellWindows ;------------------------------------------------------------------------------------------ ; Check to verify that the window object is a valid browser, if not, skip it ; ; Setup internal error handler to Trap COM errors, turn off error notification, ; check object property validity, set a flag and reset error handler and notification ; $f_isBrowser = True ; Turn off error notification for internal processing $f_NotifyStatus = _IEErrorNotify() ; save current error notify status _IEErrorNotify(False) ; Check conditions to verify that the object is a browser If $f_isBrowser Then $s_tmp = $o_window.type ; Is .type a valid property? If @error Then $f_isBrowser = False EndIf If $f_isBrowser Then $s_tmp = $o_window.document.title ; Does object have a .document and .title property? If @error Then $f_isBrowser = False EndIf ; restore error notify _IEErrorNotify($f_NotifyStatus) ; restore notification status ;------------------------------------------------------------------------------------------ If $f_isBrowser Then Switch $s_mode Case "title" If StringInStr($o_window.document.title, $s_string) > 0 Then If $i_instance = $i_tmp Then Return SetError($_IEStatus_Success, 0, $o_window) Else $i_tmp += 1 EndIf EndIf Case "instance" If $i_instance = $i_tmp Then Return SetError($_IEStatus_Success, 0, $o_window) Else $i_tmp += 1 EndIf Case "windowtitle" Local $f_found = False $s_tmp = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\", "Window Title") If Not @error Then If StringInStr($o_window.document.title & " - " & $s_tmp, $s_string) Then $f_found = True Else If StringInStr($o_window.document.title & " - Microsoft Internet Explorer", $s_string) Then $f_found = True If StringInStr($o_window.document.title & " - Windows Internet Explorer", $s_string) Then $f_found = True EndIf If $f_found Then If $i_instance = $i_tmp Then Return SetError($_IEStatus_Success, 0, $o_window) Else $i_tmp += 1 EndIf EndIf Case "url" If StringInStr($o_window.LocationURL, $s_string) > 0 Then If $i_instance = $i_tmp Then Return SetError($_IEStatus_Success, 0, $o_window) Else $i_tmp += 1 EndIf EndIf Case "text" If StringInStr($o_window.document.body.innerText, $s_string) > 0 Then If $i_instance = $i_tmp Then Return SetError($_IEStatus_Success, 0, $o_window) Else $i_tmp += 1 EndIf EndIf Case "html" If StringInStr($o_window.document.body.innerHTML, $s_string) > 0 Then If $i_instance = $i_tmp Then Return SetError($_IEStatus_Success, 0, $o_window) Else $i_tmp += 1 EndIf EndIf Case "hwnd" If $i_instance > 1 Then $i_instance = 1 __IEErrorNotify("Warning", "_IEAttach", "$_IEStatus_GeneralError", "$i_instance > 1 invalid with HWnd. Setting to 1.") EndIf If _IEPropertyGet($o_window, "hwnd") = $s_string Then Return SetError($_IEStatus_Success, 0, $o_window) EndIf Case Else ; Invalid Mode __IEErrorNotify("Error", "_IEAttach", "$_IEStatus_InvalidValue", "Invalid Mode Specified") Return SetError($_IEStatus_InvalidValue, 2, 0) EndSwitch EndIf Next __IEErrorNotify("Warning", "_IEAttach", "$_IEStatus_NoMatch") Return SetError($_IEStatus_NoMatch, 1, 0) EndFunc ;==>_IEAttach ; #FUNCTION# ==================================================================================================================== ; Name...........: _IELoadWait ; Description ...: Wait for a browser page load to complete before returning ; Parameters ....: $o_object - Object variable of an InternetExplorer.Application ; $i_delay - Optional: Milliseconds to wait before checking status ; $i_timeout - Optional: Period of time to wait before exiting function ; (default = 300000 ms aka 5 min) ; Return values .: On Success - Returns 1 ; On Failure - Returns 0 and sets @error ; @error - 0 ($_IEStatus_Success) = No Error ; - 1 ($_IEStatus_GeneralError) = General Error ; - 3 ($_IEStatus_InvalidDataType) = Invalid Data Type ; - 4 ($_IEStatus_InvalidObjectType) = Invalid Object Type ; - 6 ($_IEStatus_LoadWaitTimeout) = Load Wait Timeout ; - 8 ($_IEStatus_AccessIsDenied) = Access Is Denied ; - 9 ($_IEStatus_ClientDisconnected) = Client Disconnected ; @extended - Contains invalid parameter number ; Author ........: Dale Hohm ; ; Remarks .......: Error codes are found in Winerror.h supplied with Visual C++ and also on MSDN ; http://support.microsoft.com/kb/186063 ; ; There appear to be multiple error numbers besides 169 assigned to the "Access is Denied" description. This version ; uses an OR condition rather than an AND to try to capture these. This will be an issue in non-English language ; versions of windows where the description string will not match for those other error numbers. More research needed. ; =============================================================================================================================== Func _IELoadWait(ByRef $o_object, $i_delay = 0, $i_timeout = -1) If Not IsObj($o_object) Then __IEErrorNotify("Error", "_IELoadWait", "$_IEStatus_InvalidDataType") Return SetError($_IEStatus_InvalidDataType, 1, 0) EndIf If Not __IEIsObjType($o_object, "browserdom") Then __IEErrorNotify("Error", "_IELoadWait", "$_IEStatus_InvalidObjectType", ObjName($o_object)) Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf Local $oTemp, $f_Abort = False, $i_ErrorStatusCode = $_IEStatus_Success ; Turn off error notification for internal processing Local $f_NotifyStatus = _IEErrorNotify() ; save current error notify status _IEErrorNotify(False) Sleep($i_delay) ; Local $s_error Local $IELoadWaitTimer = TimerInit() If $i_timeout = -1 Then $i_timeout = $__IELoadWaitTimeout Select Case __IEIsObjType($o_object, "browser"); InternetExplorer While Not (String($o_object.readyState) = "complete" Or $o_object.readyState = 4 Or $f_Abort) ; Trap unrecoverable COM errors If @error Then $s_error = @error If __IEComErrorUnrecoverable($s_error) Then $i_ErrorStatusCode = __IEComErrorUnrecoverable($s_error) $f_Abort = True EndIf EndIf If (TimerDiff($IELoadWaitTimer) > $i_timeout) Then $i_ErrorStatusCode = $_IEStatus_LoadWaitTimeout $f_Abort = True EndIf Sleep(100) WEnd While Not (String($o_object.document.readyState) = "complete" Or $o_object.document.readyState = 4 Or $f_Abort) ; Trap unrecoverable COM errors If @error Then $s_error = @error If __IEComErrorUnrecoverable($s_error) Then $i_ErrorStatusCode = __IEComErrorUnrecoverable($s_error) $f_Abort = True EndIf EndIf If (TimerDiff($IELoadWaitTimer) > $i_timeout) Then $i_ErrorStatusCode = $_IEStatus_LoadWaitTimeout $f_Abort = True EndIf Sleep(100) WEnd Case __IEIsObjType($o_object, "window") ; Window, Frame, iFrame While Not (String($o_object.document.readyState) = "complete" Or $o_object.document.readyState = 4 Or $f_Abort) ; Trap unrecoverable COM errors If @error Then $s_error = @error If __IEComErrorUnrecoverable($s_error) Then $i_ErrorStatusCode = __IEComErrorUnrecoverable($s_error) $f_Abort = True EndIf EndIf If (TimerDiff($IELoadWaitTimer) > $i_timeout) Then $i_ErrorStatusCode = $_IEStatus_LoadWaitTimeout $f_Abort = True EndIf Sleep(100) WEnd While Not (String($o_object.top.document.readyState) = "complete" Or $o_object.top.document.readyState = 4 Or $f_Abort) ; Trap unrecoverable COM errors If @error Then $s_error = @error If __IEComErrorUnrecoverable($s_error) Then $i_ErrorStatusCode = __IEComErrorUnrecoverable($s_error) $f_Abort = True EndIf EndIf If (TimerDiff($IELoadWaitTimer) > $i_timeout) Then $i_ErrorStatusCode = $_IEStatus_LoadWaitTimeout $f_Abort = True EndIf Sleep(100) WEnd Case __IEIsObjType($o_object, "document") ; Document $oTemp = $o_object.parentWindow While Not (String($oTemp.document.readyState) = "complete" Or $oTemp.document.readyState = 4 Or $f_Abort) ; Trap unrecoverable COM errors If @error Then $s_error = @error If __IEComErrorUnrecoverable($s_error) Then $i_ErrorStatusCode = __IEComErrorUnrecoverable($s_error) $f_Abort = True EndIf EndIf If (TimerDiff($IELoadWaitTimer) > $i_timeout) Then $i_ErrorStatusCode = $_IEStatus_LoadWaitTimeout $f_Abort = True EndIf Sleep(100) WEnd While Not (String($oTemp.top.document.readyState) = "complete" Or $oTemp.top.document.readyState = 4 Or $f_Abort) ; Trap unrecoverable COM errors If @error Then $s_error = @error If __IEComErrorUnrecoverable($s_error) Then $i_ErrorStatusCode = __IEComErrorUnrecoverable($s_error) $f_Abort = True EndIf EndIf If (TimerDiff($IELoadWaitTimer) > $i_timeout) Then $i_ErrorStatusCode = $_IEStatus_LoadWaitTimeout $f_Abort = True EndIf Sleep(100) WEnd Case Else ; this should work with any other DOM object $oTemp = $o_object.document.parentWindow While Not (String($oTemp.document.readyState) = "complete" Or $oTemp.document.readyState = 4 Or $f_Abort) ; Trap unrecoverable COM errors If @error Then $s_error = @error If __IEComErrorUnrecoverable($s_error) Then $i_ErrorStatusCode = __IEComErrorUnrecoverable($s_error) $f_Abort = True EndIf EndIf If (TimerDiff($IELoadWaitTimer) > $i_timeout) Then $i_ErrorStatusCode = $_IEStatus_LoadWaitTimeout $f_Abort = True EndIf Sleep(100) WEnd While Not (String($oTemp.top.document.readyState) = "complete" Or $o_object.top.document.readyState = 4 Or $f_Abort) ; Trap unrecoverable COM errors If @error Then $s_error = @error If __IEComErrorUnrecoverable($s_error) Then $i_ErrorStatusCode = __IEComErrorUnrecoverable($s_error) $f_Abort = True EndIf EndIf If (TimerDiff($IELoadWaitTimer) > $i_timeout) Then $i_ErrorStatusCode = $_IEStatus_LoadWaitTimeout $f_Abort = True EndIf Sleep(100) WEnd EndSelect ; restore error notify _IEErrorNotify($f_NotifyStatus) ; restore notification status Switch $i_ErrorStatusCode Case $_IEStatus_Success Return SetError($_IEStatus_Success, 0, 1) Case $_IEStatus_LoadWaitTimeout __IEErrorNotify("Warning", "_IELoadWait", "$_IEStatus_LoadWaitTimeout") Return SetError($_IEStatus_LoadWaitTimeout, 3, 0) Case $_IEStatus_AccessIsDenied __IEErrorNotify("Warning", "_IELoadWait", "$_IEStatus_AccessIsDenied", _ "Cannot verify readyState. Likely casue: cross-domain scripting security restriction. (" & $s_error & ")") Return SetError($_IEStatus_AccessIsDenied, 0, 0) Case $_IEStatus_ClientDisconnected __IEErrorNotify("Error", "_IELoadWait", "$_IEStatus_ClientDisconnected", _ $s_error & ", Browser has been deleted prior to operation.") Return SetError($_IEStatus_ClientDisconnected, 0, 0) Case Else __IEErrorNotify("Error", "_IELoadWait", "$_IEStatus_GeneralError", "Invalid Error Status - Notify IE.au3 developer") Return SetError($_IEStatus_GeneralError, 0, 0) EndSwitch EndFunc ;==>_IELoadWait ; #FUNCTION# ==================================================================================================================== ; Name...........: _IELoadWaitTimeout ; Description ...: Retrieve or set the current value in milliseconds _IELoadWait will try before timing out ; Parameters ....: $i_timeout - Optional: retrieve or specify the number of milliseconds ; - 0 or positive integer sets timeout to this value ; - -1 = (Default) returns the current timeout value ; (stored in global variable $__IELoadWaitTimeout) ; Return values .: On Success - If $i_timeout = -1, returns the current timeout value, else returns 1 ; On Failure - None ; Author ........: Dale Hohm ; =============================================================================================================================== Func _IELoadWaitTimeout($i_timeout = -1) If $i_timeout = -1 Then Return SetError($_IEStatus_Success, 0, $__IELoadWaitTimeout) Else $__IELoadWaitTimeout = $i_timeout Return SetError($_IEStatus_Success, 0, 1) EndIf EndFunc ;==>_IELoadWaitTimeout #endregion Core functions #region Frame Functions ; Security Note on Frame functions: ; Note that security restriction in Internet Explorer related to cross-site scripting ; between frames can cause serious problems with the frame functions. Functions that ; work connected to one site will fail when connected to another depending on the sites ; referenced in the frames. In general, if all the referenced pages are on the same ; webserver these functions should work as described; if not, unexpected COM failures ; can occur. ; #FUNCTION# ==================================================================================================================== ; Name...........: _IEIsFrameSet ; Description ...: Checks to see if the specified Window contains a FrameSet ; Parameters ....: $o_object - Object variable of an InternetExplorer.Application, Window or Frame object ; Return values .: On Success - Returns 1 if the object references a FrameSet page ; On Failure - Returns 0 and sets @error ; @error - 0 ($_IEStatus_Success) = No Error ; - 3 ($_IEStatus_InvalidDataType) = Invalid Data Type ; @extended - Contains invalid parameter number ; Author ........: Dale Hohm ; =============================================================================================================================== Func _IEIsFrameSet(ByRef $o_object) ; Note: this is more reliable test for a FrameSet than checking the ; number of frames (document.frames.length) because iFrames embedded on a normal ; page are included in the frame collection even though it is not a FrameSet If Not IsObj($o_object) Then __IEErrorNotify("Error", "_IEIsFrameSet", "$_IEStatus_InvalidDataType") Return SetError($_IEStatus_InvalidDataType, 1, 0) EndIf ; If String($o_object.document.body.tagName) = "FRAMESET" Then Return SetError($_IEStatus_Success, 0, 1) Else If @error Then ; Trap COM error, report and return Local $s_error = @error, $s_function_name = "_IEIsFrameSet" __IEErrorNotify("Error", $s_function_name, "$_IEStatus_COMError", $s_error) Return SetError($_IEStatus_ComError, $s_error, 0) EndIf Return SetError($_IEStatus_Success, 0, 0) EndIf EndFunc ;==>_IEIsFrameSet ; #FUNCTION# ==================================================================================================================== ; Name...........: _IEFrameGetCollection ; Description ...: Returns a collection object containing the frames in a FrameSet or the iFrames on a normal page ; Parameters ....: $o_object - Object variable of an InternetExplorer.Application, Window or Frame object ; $i_index - Optional: specifies whether to return a collection or indexed instance ; - 0 or positive integer returns an indexed instance ; - -1 = (Default) returns a collection ; Return values .: On Success - Returns an object variable containing the Frames collection, @extended = Frame count ; On Failure - Returns 0 and sets @error ; @error - 0 ($_IEStatus_Success) = No Error ; - 3 ($_IEStatus_InvalidDataType) = Invalid Data Type ; - 5 ($_IEStatus_InvalidValue) = Invalid Value ; - 7 ($_IEStatus_NoMatch) = No Match ; @extended - Contains invalid parameter number ; Author ........: Dale Hohm ; =============================================================================================================================== Func _IEFrameGetCollection(ByRef $o_object, $i_index = -1) If Not IsObj($o_object) Then __IEErrorNotify("Error", "_IEFrameGetCollection", "$_IEStatus_InvalidDataType") Return SetError($_IEStatus_InvalidDataType, 1, 0) EndIf ; $i_index = Number($i_index) Select Case $i_index = -1 Return SetError($_IEStatus_Success, $o_object.document.parentwindow.frames.length, _ $o_object.document.parentwindow.frames) Case $i_index > -1 And $i_index < $o_object.document.parentwindow.frames.length Return SetError($_IEStatus_Success, $o_object.document.parentwindow.frames.length, _ $o_object.document.parentwindow.frames.item($i_index)) Case $i_index < -1 __IEErrorNotify("Error", "_IEFrameGetCollection", "$_IEStatus_InvalidValue", "$i_index < -1") Return SetError($_IEStatus_InvalidValue, 2, 0) Case Else __IEErrorNotify("Warning", "_IEFrameGetCollection", "$_IEStatus_NoMatch") Return SetError($_IEStatus_NoMatch, 2, 0) EndSelect EndFunc ;==>_IEFrameGetCollection ; #FUNCTION# ==================================================================================================================== ; Name...........: _IEFrameGetObjByName ; Description ...: Returns an object reference to a Frame by name ; Parameters ....: $o_object - Object variable of an InternetExplorer.Application, Window or Frame object ; $s_name - Name of the Frame you wish to match ; Return values .: On Success - Returns an object variable pointing to the Window object in a Frame, @extended = Frame count ; On Failure - Returns 0 and sets @error ; @error - 0 ($_IEStatus_Success) = No Error ; - 3 ($_IEStatus_InvalidDataType) = Invalid Data Type ; - 4 ($_IEStatus_InvalidObjectType) = Invalid Object Type ; - 7 ($_IEStatus_NoMatch) = No Match ; @extended - Contains invalid parameter number ; Author ........: Dale Hohm ; =============================================================================================================================== Func _IEFrameGetObjByName(ByRef $o_object, $s_Name) If Not IsObj($o_object) Then __IEErrorNotify("Error", "_IEFrameGetObjByName", "$_IEStatus_InvalidDataType") Return SetError($_IEStatus_InvalidDataType, 1, 0) EndIf ; Local $oTemp, $oFrames If Not __IEIsObjType($o_object, "browserdom") Then __IEErrorNotify("Error", "_IEFrameGetObjByName", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf If __IEIsObjType($o_object, "document") Then $oTemp = $o_object.parentWindow Else $oTemp = $o_object.document.parentWindow EndIf If _IEIsFrameSet($oTemp) Then $oFrames = _IETagNameGetCollection($oTemp, "frame") Else $oFrames = _IETagNameGetCollection($oTemp, "iframe") EndIf If $oFrames.length Then For $oFrame In $oFrames If String($oFrame.name) = $s_Name Then Return SetError($_IEStatus_Success, 0, $oTemp.frames($s_Name)) Next __IEErrorNotify("Warning", "_IEFrameGetObjByName", "$_IEStatus_NoMatch", "No frames matching name") Return SetError($_IEStatus_NoMatch, 2, 0) Else __IEErrorNotify("Warning", "_IEFrameGetObjByName", "$_IEStatus_NoMatch", "No Frames found") Return SetError($_IEStatus_NoMatch, 2, 0) EndIf EndFunc ;==>_IEFrameGetObjByName #endregion Frame Functions #region Link functions ; #FUNCTION# ==================================================================================================================== ; Name...........: _IELinkClickByText ; Description ...: Simulate a mouse click on a link with text sub-string matching the string provided ; Parameters ....: $o_object - Object variable of an InternetExplorer.Application, Window or Frame object ; $s_linkText - Text displayed on the web page for the desired link to click ; $i_index - Optional: If the link text occurs more than once, specify which instance ; you want to click by 0-based index ; $f_wait - Optional: specifies whether to wait for page to load before returning ; 0 = Return immediately, not waiting for page to load ; 1 = (Default) Wait for page load to complete before returning ; Return values .: On Success - Returns -1 ; On Failure - Returns 0 and sets @error ; @error - 0 ($_IEStatus_Success) = No Error ; - 1 ($_IEStatus_GeneralError) = General Error ; - 3 ($_IEStatus_InvalidDataType) = Invalid Data Type ; - 4 ($_IEStatus_InvalidObjectType) = Invalid Object Type ; - 6 ($_IEStatus_LoadWaitTimeout) = Load Wait Timeout ; - 7 ($_IEStatus_NoMatch) = No Match ; - 8 ($_IEStatus_AccessIsDenied) = Access Is Denied ; - 9 ($_IEStatus_ClientDisconnected) = Client Disconnected ; @extended - Contains invalid parameter number ; Author ........: Dale Hohm ; =============================================================================================================================== Func _IELinkClickByText(ByRef $o_object, $s_linkText, $i_index = 0, $f_wait = 1) If Not IsObj($o_object) Then __IEErrorNotify("Error", "_IELinkClickByText", "$_IEStatus_InvalidDataType") Return SetError($_IEStatus_InvalidDataType, 1, 0) EndIf ; Local $found = 0, $linktext, $links = $o_object.document.links $i_index = Number($i_index) For $link In $links $linktext = String($link.outerText) If $linktext = $s_linkText Then If ($found = $i_index) Then $link.click() If @error Then ; Trap COM error, report and return Local $s_error = @error, $s_function_name = "_IELinkClickByText" __IEErrorNotify("Error", $s_function_name, "$_IEStatus_COMError", $s_error) Return SetError($_IEStatus_ComError, $s_error, 0) EndIf If $f_wait Then _IELoadWait($o_object) Return SetError(@error, 0, -1) EndIf Return SetError($_IEStatus_Success, 0, -1) EndIf $found = $found + 1 EndIf Next __IEErrorNotify("Warning", "_IELinkClickByText", "$_IEStatus_NoMatch") Return SetError($_IEStatus_NoMatch, 0, 0) ; Could be caused by parameter 2, 3 or both EndFunc ;==>_IELinkClickByText ; #FUNCTION# ==================================================================================================================== ; Name...........: _IELinkClickByIndex ; Description ...: Simulate a mouse click on a link by 0-based index (in source order) ; Parameters ....: $o_object - Object variable of an InternetExplorer.Application, Window or Frame object ; $i_index - Optional: 0-based index of the link you wish to match ; $f_wait - Optional: specifies whether to wait for page to load before returning ; 0 = Return immediately, not waiting for page to load ; 1 = (Default) Wait for page load to complete before returning ; Return values .: On Success - Returns -1 ; On Failure - Returns 0 and sets @error ; @error - 0 ($_IEStatus_Success) = No Error ; - 1 ($_IEStatus_GeneralError) = General Error ; - 3 ($_IEStatus_InvalidDataType) = Invalid Data Type ; - 4 ($_IEStatus_InvalidObjectType) = Invalid Object Type ; - 6 ($_IEStatus_LoadWaitTimeout) = Load Wait Timeout ; - 7 ($_IEStatus_NoMatch) = No Match ; - 8 ($_IEStatus_AccessIsDenied) = Access Is Denied ; - 9 ($_IEStatus_ClientDisconnected) = Client Disconnected ; @extended - Contains invalid parameter number ; Author ........: Dale Hohm ; =============================================================================================================================== Func _IELinkClickByIndex(ByRef $o_object, $i_index, $f_wait = 1) If Not IsObj($o_object) Then __IEErrorNotify("Error", "_IELinkClickByIndex", "$_IEStatus_InvalidDataType") Return SetError($_IEStatus_InvalidDataType, 1, 0) EndIf ; Local $oLinks = $o_object.document.links, $oLink $i_index = Number($i_index) If ($i_index >= 0) And ($i_index <= $oLinks.length - 1) Then $oLink = $oLinks($i_index) $oLink.click() If @error Then ; Trap COM error, report and return Local $s_error = @error, $s_function_name = "_IELinkClickByIndex" __IEErrorNotify("Error", $s_function_name, "$_IEStatus_COMError", $s_error) Return SetError($_IEStatus_ComError, $s_error, 0) EndIf If $f_wait Then _IELoadWait($o_object) Return SetError(@error, 0, -1) EndIf Return SetError($_IEStatus_Success, 0, -1) Else __IEErrorNotify("Warning", "_IELinkClickByIndex", "$_IEStatus_NoMatch") Return SetError($_IEStatus_NoMatch, 2, 0) EndIf EndFunc ;==>_IELinkClickByIndex ; #FUNCTION# ==================================================================================================================== ; Name...........: _IELinkGetCollection ; Description ...: Returns a collection object containing all links in the document ; Parameters ....: $o_object - Object variable of an InternetExplorer.Application, Window or Frame object ; $i_index - Optional: specifies whether to return a collection or indexed instance ; - 0 or positive integer returns an indexed instance ; - -1 = (Default) returns a collection ; Return values .: On Success - Returns an object collection of all links in the document, @extended = link count ; On Failure - Returns 0 and sets @error ; @error - 0 ($_IEStatus_Success) = No Error ; - 3 ($_IEStatus_InvalidDataType) = Invalid Data Type ; - 5 ($_IEStatus_InvalidValue) = Invalid Value ; - 7 ($_IEStatus_NoMatch) = No Match ; @extended - Contains invalid parameter number ; Author ........: Dale Hohm ; =============================================================================================================================== Func _IELinkGetCollection(ByRef $o_object, $i_index = -1) If Not IsObj($o_object) Then __IEErrorNotify("Error", "_IELinkGetCollection", "$_IEStatus_InvalidDataType") Return SetError($_IEStatus_InvalidDataType, 1, 0) EndIf ; $i_index = Number($i_index) Select Case $i_index = -1 Return SetError($_IEStatus_Success, $o_object.document.links.length, _ $o_object.document.links) Case $i_index > -1 And $i_index < $o_object.document.links.length Return SetError($_IEStatus_Success, $o_object.document.links.length, _ $o_object.document.links.item($i_index)) Case $i_index < -1 __IEErrorNotify("Error", "_IELinkGetCollection", "$_IEStatus_InvalidValue") Return SetError($_IEStatus_InvalidValue, 2, 0) Case Else __IEErrorNotify("Warning", "_IELinkGetCollection", "$_IEStatus_NoMatch") Return SetError($_IEStatus_NoMatch, 2, 0) EndSelect EndFunc ;==>_IELinkGetCollection #endregion Link functions #region Image functions ; #FUNCTION# ==================================================================================================================== ; Name...........: _IEImgClick ; Description ...: Simulate a mouse click on an image. Match by sub-string match of alt text, name or src ; Parameters ....: $o_object - Object variable of an InternetExplorer.Application, Window or Frame object ; $s_linkText - Text to match the content of the attribute specified in $s_mode ; $s_mode - Optional: specifies search mode ; src = (Default) match the url of the image ; name = match the name of the image ; alt = match the alternate text of the image ; $i_index - Optional: If the img text occurs more than once, specify which instance ; you want to click by 0-based index ; $f_wait - Optional: specifies whether to wait for page to load before returning ; 0 = Return immediately, not waiting for page to load ; 1 = (Default) Wait for page load to complete before returning ; Return values .: On Success - Returns -1 ; On Failure - Returns 0 and sets @error ; @error - 0 ($_IEStatus_Success) = No Error ; - 1 ($_IEStatus_GeneralError) = General Error ; - 3 ($_IEStatus_InvalidDataType) = Invalid Data Type ; - 4 ($_IEStatus_InvalidObjectType) = Invalid Object Type ; - 5 ($_IEStatus_InvalidValue) = Invalid Value ; - 6 ($_IEStatus_LoadWaitTimeout) = Load Wait Timeout ; - 7 ($_IEStatus_NoMatch) = No Match ; - 8 ($_IEStatus_AccessIsDenied) = Access Is Denied ; - 9 ($_IEStatus_ClientDisconnected) = Client Disconnected ; @extended - Contains invalid parameter number ; Author ........: Dale Hohm ; =============================================================================================================================== Func _IEImgClick(ByRef $o_object, $s_linkText, $s_mode = "src", $i_index = 0, $f_wait = 1) If Not IsObj($o_object) Then __IEErrorNotify("Error", "_IEImgClick", "$_IEStatus_InvalidDataType") Return SetError($_IEStatus_InvalidDataType, 1, 0) EndIf ; Local $linktext, $found = 0, $imgs = $o_object.document.images $s_mode = StringLower($s_mode) $i_index = Number($i_index) For $img In $imgs Select Case $s_mode = "alt" $linktext = $img.alt Case $s_mode = "name" $linktext = $img.name Case $s_mode = "src" $linktext = $img.src Case Else __IEErrorNotify("Error", "_IEImgClick", "$_IEStatus_InvalidValue", "Invalid mode: " & $s_mode) Return SetError($_IEStatus_InvalidValue, 3, 0) EndSelect If StringInStr($linktext, $s_linkText) Then If ($found = $i_index) Then $img.click() If @error Then ; Trap COM error, report and return Local $s_error = @error, $s_function_name = "_IEImgClick" __IEErrorNotify("Error", $s_function_name, "$_IEStatus_COMError", $s_error) Return SetError($_IEStatus_ComError, $s_error, 0) EndIf If $f_wait Then _IELoadWait($o_object) Return SetError(@error, 0, -1) EndIf Return SetError($_IEStatus_Success, 0, -1) EndIf $found = $found + 1 EndIf Next __IEErrorNotify("Warning", "_IEImgClick", "$_IEStatus_NoMatch") Return SetError($_IEStatus_NoMatch, 0, 0) ; Could be caused by parameter 2, 4 or both EndFunc ;==>_IEImgClick ; #FUNCTION# ==================================================================================================================== ; Name...........: _IEImgGetCollection ; Description ...: Returns a collection object variable representing the IMG tags in the document ; Parameters ....: $o_object - Object variable of an InternetExplorer.Application, Window, Frame or iFrame object ; $i_index - Optional: specifies whether to return a collection or indexed instance ; - 0 or positive integer returns an indexed instance ; - -1 = (Default) returns a collection ; Return values .: On Success - Returns an object variable with a collection of all IMG tags in the document, @extended = img count ; On Failure - Returns 0 and sets @error ; @error - 0 ($_IEStatus_Success) = No Error ; - 3 ($_IEStatus_InvalidDataType) = Invalid Data Type ; - 5 ($_IEStatus_InvalidValue) = Invalid Value ; - 7 ($_IEStatus_NoMatch) = No Match ; @extended - Contains invalid parameter number ; Author ........: Dale Hohm ; =============================================================================================================================== Func _IEImgGetCollection(ByRef $o_object, $i_index = -1) If Not IsObj($o_object) Then __IEErrorNotify("Error", "_IEImgGetCollection", "$_IEStatus_InvalidDataType") Return SetError($_IEStatus_InvalidDataType, 1, 0) EndIf ; Local $oTemp = _IEDocGetObj($o_object) $i_index = Number($i_index) Select Case $i_index = -1 Return SetError($_IEStatus_Success, $oTemp.images.length, $oTemp.images) Case $i_index > -1 And $i_index < $oTemp.images.length Return SetError($_IEStatus_Success, $oTemp.images.length, $oTemp.images.item($i_index)) Case $i_index < -1 __IEErrorNotify("Error", "_IEImgGetCollection", "$_IEStatus_InvalidValue", "$i_index < -1") Return SetError($_IEStatus_InvalidValue, 2, 0) Case Else __IEErrorNotify("Warning", "_IEImgGetCollection", "$_IEStatus_NoMatch") Return SetError($_IEStatus_NoMatch, 1, 0) EndSelect EndFunc ;==>_IEImgGetCollection #endregion Image functions #region Form functions ; #FUNCTION# ==================================================================================================================== ; Name...........: _IEFormGetCollection ; Description ...: Returns a collection object variable representing the Forms in the document ; Parameters ....: $o_object - Object variable of an InternetExplorer.Application, Window, Frame or iFrame object ; $i_index - Optional: specifies whether to return a collection or indexed instance ; - 0 or positive integer returns an indexed instance ; - -1 = (Default) returns a collection ; Return values .: On Success - Returns an object variable with a collection of all forms in the document, @extended = form count ; On Failure - Returns 0 and sets @error ; @error - 0 ($_IEStatus_Success) = No Error ; - 3 ($_IEStatus_InvalidDataType) = Invalid Data Type ; - 5 ($_IEStatus_InvalidValue) = Invalid Value ; - 7 ($_IEStatus_NoMatch) = No Match ; @extended - Contains invalid parameter number ; Author ........: Dale Hohm ; =============================================================================================================================== Func _IEFormGetCollection(ByRef $o_object, $i_index = -1) If Not IsObj($o_object) Then __IEErrorNotify("Error", "_IEFormGetCollection", "$_IEStatus_InvalidDataType") Return SetError($_IEStatus_InvalidDataType, 1, 0) EndIf ; Local $oTemp = _IEDocGetObj($o_object) $i_index = Number($i_index) Select Case $i_index = -1 Return SetError($_IEStatus_Success, $oTemp.forms.length, $oTemp.forms) Case $i_index > -1 And $i_index < $oTemp.forms.length Return SetError($_IEStatus_Success, $oTemp.forms.length, $oTemp.forms.item($i_index)) Case $i_index < -1 __IEErrorNotify("Error", "_IEFormGetCollection", "$_IEStatus_InvalidValue", "$i_index < -1") Return SetError($_IEStatus_InvalidValue, 2, 0) Case Else __IEErrorNotify("Warning", "_IEFormGetCollection", "$_IEStatus_NoMatch") Return SetError($_IEStatus_NoMatch, 1, 0) EndSelect EndFunc ;==>_IEFormGetCollection ; #FUNCTION# ==================================================================================================================== ; Name...........: _IEFormGetObjByName ; Description ...: Returns an object reference to a Form by name ; Parameters ....: $o_object - Object variable of an InternetExplorer.Application, Window or Frame object ; $s_name - Specifies the name of the Form you wish to match ; $i_index - Optional: If Form name occurs more than once, specifies instance by 0-based index ; - 0 (Default) or positive integer returns an indexed instance ; - -1 returns a collection of the specified Forms ; Return values .: On Success - Returns an object variable pointing to the Form object, @extended = form count ; On Failure - Returns 0 and sets @error ; @error - 0 ($_IEStatus_Success) = No Error ; - 3 ($_IEStatus_InvalidDataType) = Invalid Data Type ; - 7 ($_IEStatus_NoMatch) = No Match ; @extended - Contains invalid parameter number ; Author ........: Dale Hohm ; =============================================================================================================================== Func _IEFormGetObjByName(ByRef $o_object, $s_Name, $i_index = 0) If Not IsObj($o_object) Then __IEErrorNotify("Error", "_IEFormGetObjByName", "$_IEStatus_InvalidDataType") Return SetError($_IEStatus_InvalidDataType, 1, 0) EndIf ; ;----- Determine valid collection length Local $i_length = 0 Local $o_col = $o_object.document.forms.item($s_Name) If IsObj($o_col) Then If __IEIsObjType($o_col, "elementcollection") Then $i_length = $o_col.length Else $i_length = 1 EndIf EndIf ;----- $i_index = Number($i_index) If $i_index = -1 Then Return SetError($_IEStatus_Success, $i_length, $o_object.document.forms.item($s_Name)) Else If IsObj($o_object.document.forms.item($s_Name, $i_index)) Then Return SetError($_IEStatus_Success, $i_length, $o_object.document.forms.item($s_Name, $i_index)) Else __IEErrorNotify("Warning", "_IEFormGetObjByName", "$_IEStatus_NoMatch") Return SetError($_IEStatus_NoMatch, 0, 0) ; Could be caused by parameter 2, 3 or both EndIf EndIf EndFunc ;==>_IEFormGetObjByName ; #FUNCTION# ==================================================================================================================== ; Name...........: _IEFormElementGetCollection ; Description ...: Returns a collection object variable representing all Form Elements within a given Form ; Parameters ....: $o_object - Object variable of an InternetExplorer.Application, Form object ; $i_index - Optional: specifies whether to return a collection or indexed instance ; - 0 or positive integer returns an indexed instance ; - -1 = (Default) returns a collection ; Return values .: On Success - Returns an object variable containing the Form Elements collection, @extended = form element count ; On Failure - Returns 0 and sets @error ; @error - 0 ($_IEStatus_Success) = No Error ; - 3 ($_IEStatus_InvalidDataType) = Invalid Data Type ; - 4 ($_IEStatus_InvalidObjectType) = Invalid Object Type ; - 5 ($_IEStatus_InvalidValue) = Invalid Value ; - 7 ($_IEStatus_NoMatch) = No Match ; @extended - Contains invalid parameter number ; Author ........: Dale Hohm ; =============================================================================================================================== Func _IEFormElementGetCollection(ByRef $o_object, $i_index = -1) If Not IsObj($o_object) Then __IEErrorNotify("Error", "_IEFormElementGetCollection", "$_IEStatus_InvalidDataType") Return SetError($_IEStatus_InvalidDataType, 1, 0) EndIf ; If Not __IEIsObjType($o_object, "form") Then __IEErrorNotify("Error", "_IEFormElementGetCollection", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf ; $i_index = Number($i_index) Select Case $i_index = -1 Return SetError($_IEStatus_Success, $o_object.elements.length, $o_object.elements) Case $i_index > -1 And $i_index < $o_object.elements.length Return SetError($_IEStatus_Success, $o_object.elements.length, $o_object.elements.item($i_index)) Case $i_index < -1 __IEErrorNotify("Error", "_IEFormElementGetCollection", "$_IEStatus_InvalidValue", "$i_index < -1") Return SetError($_IEStatus_InvalidValue, 2, 0) Case Else Return SetError($_IEStatus_NoMatch, 1, 0) EndSelect EndFunc ;==>_IEFormElementGetCollection ; #FUNCTION# ==================================================================================================================== ; Name...........: _IEFormElementGetObjByName ; Description ...: Returns an object reference to a Form Element by name ; Parameters ....: $o_object - Object variable of an InternetExplorer.Application, Form object ; $s_name - Specifies the name of the Form Element you wish to match ; $i_index - Optional: If the Form Element name occurs more than once, specifies instance by 0-based index ; - 0 (Default) or positive integer returns an indexed instance ; - -1 returns a collection of the specified Form Elements ; Return values .: On Success - Returns an object variable pointing to the Form Element object, @extended = form count ; On Failure - Returns 0 and sets @error ; @error - 0 ($_IEStatus_Success) = No Error ; - 3 ($_IEStatus_InvalidDataType) = Invalid Data Type ; - 4 ($_IEStatus_InvalidObjectType) = Invalid Object Type ; - 7 ($_IEStatus_NoMatch) = No Match ; @extended - Contains invalid parameter number ; Author ........: Dale Hohm ; =============================================================================================================================== Func _IEFormElementGetObjByName(ByRef $o_object, $s_Name, $i_index = 0) If Not IsObj($o_object) Then __IEErrorNotify("Error", "_IEFormElementGetObjByName", "$_IEStatus_InvalidDataType") Return SetError($_IEStatus_InvalidDataType, 1, 0) EndIf ; If Not __IEIsObjType($o_object, "form") Then __IEErrorNotify("Error", "_IEFormElementGetObjByName", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf ; ;----- Determine valid collection length Local $i_length = 0 Local $o_col = $o_object.elements.item($s_Name) If IsObj($o_col) Then If __IEIsObjType($o_col, "elementcollection") Then $i_length = $o_col.length Else $i_length = 1 EndIf EndIf ;----- $i_index = Number($i_index) If $i_index = -1 Then Return SetError($_IEStatus_Success, $i_length, $o_object.elements.item($s_Name)) Else If IsObj($o_object.elements.item($s_Name, $i_index)) Then Return SetError($_IEStatus_Success, $i_length, $o_object.elements.item($s_Name, $i_index)) Else __IEErrorNotify("Warning", "_IEFormElementGetObjByName", "$_IEStatus_NoMatch") Return SetError($_IEStatus_NoMatch, 0, 0) ; Could be caused by parameter 2, 3 or both EndIf EndIf EndFunc ;==>_IEFormElementGetObjByName ; #FUNCTION# ==================================================================================================================== ; Name...........: _IEFormElementGetValue ; Description ...: Returns the value of a given Form Element ; Parameters ....: $o_object - Object variable of an InternetExplorer.Application, Form Element object ; Return values .: On Success - Returns the string value of the given Form Element ; On Failure - Returns 0 and sets @error ; @error - 0 ($_IEStatus_Success) = No Error ; - 3 ($_IEStatus_InvalidDataType) = Invalid Data Type ; - 4 ($_IEStatus_InvalidObjectType) = Invalid Object Type ; @extended - Contains invalid parameter number ; Author ........: Dale Hohm ; =============================================================================================================================== Func _IEFormElementGetValue(ByRef $o_object) If Not IsObj($o_object) Then __IEErrorNotify("Error", "_IEFormElementGetValue", "$_IEStatus_InvalidDataType") Return SetError($_IEStatus_InvalidDataType, 1, 0) EndIf ; If Not __IEIsObjType($o_object, "forminputelement") Then __IEErrorNotify("Error", "_IEFormElementGetValue", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf ; Local $s_return = String($o_object.value) If @error Then ; Trap COM error, report and return Local $s_error = @error, $s_function_name = "_IEFormElementGetValue" __IEErrorNotify("Error", $s_function_name, "$_IEStatus_COMError", $s_error) Return SetError($_IEStatus_ComError, $s_error, 0) EndIf SetError($_IEStatus_Success) Return $s_return EndFunc ;==>_IEFormElementGetValue ; #FUNCTION# ==================================================================================================================== ; Name...........: _IEFormElementSetValue ; Description ...: Set the value of a specified Form Element ; Parameters ....: $o_object - Object variable of an InternetExplorer.Application, Form Element object ; $s_newvalue - The new value to be set into the Form Element ; $f_fireEvent- Optional: specifies whether to fire an OnChange event after changing value ; 0 = Do not fire OnChange event after setting value ; 1 = (Default) fire OnChange event after setting value ; Return values .: On Success - Returns 1 ; On Failure - Returns 0 and sets @error ; @error - 0 ($_IEStatus_Success) = No Error ; - 3 ($_IEStatus_InvalidDataType) = Invalid Data Type ; - 4 ($_IEStatus_InvalidObjectType) = Invalid Object Type ; @extended - Contains invalid parameter number ; Author ........: Dale Hohm ; =============================================================================================================================== Func _IEFormElementSetValue(ByRef $o_object, $s_newvalue, $f_fireEvent = 1) If Not IsObj($o_object) Then __IEErrorNotify("Error", "_IEFormElementSetValue", "$_IEStatus_InvalidDataType") Return SetError($_IEStatus_InvalidDataType, 1, 0) EndIf ; If Not __IEIsObjType($o_object, "forminputelement") Then __IEErrorNotify("Error", "_IEFormElementSetValue", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf ; If String($o_object.type) = "file" Then __IEErrorNotify("Error", "_IEFormElementSetValue", "$_IEStatus_InvalidObjectType", "Browser securuty prevents SetValue of TYPE=FILE") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf ; $o_object.value = $s_newvalue If @error Then ; Trap COM error, report and return Local $s_error = @error, $s_function_name = "_IEFormElementSetValue" __IEErrorNotify("Error", $s_function_name, "$_IEStatus_COMError", $s_error) Return SetError($_IEStatus_ComError, $s_error, 0) EndIf If $f_fireEvent Then $o_object.fireEvent("OnChange") $o_object.fireEvent("OnClick") EndIf Return SetError($_IEStatus_Success, 0, 1) EndFunc ;==>_IEFormElementSetValue ; #FUNCTION# ==================================================================================================================== ; Name...........: _IEFormElementOptionSelect ; Description ...: Set the value of a specified form element ; Parameters ....: $o_object - Form Element Object of type "Select Option" ; $s_string - Value used to match element - treatment based on $s_mode ; $f_select - Optional: specifies whether element should be selected or deselected ; -1 = Return selected state ; 0 = Deselect the element ; 1 = (Default) Select the element ; $s_mode - Optional: specifies search mode ; byValue = (Default) value of the option you wish to select ; byText = text of the option you wish to select ; byIndex = 0-based index of option you wish to select ; $f_fireEvent- Optional: specifies whether to fire an OnChange event after changing value ; 0 = do not fire OnChange event after setting value ; 1 = (Default) fire OnChange event after setting value ; Return values .: On Success - If $f_select = -1, returns the current selected state, else returns 1 ; On Failure - Returns 0 and sets @error ; @error - 0 ($_IEStatus_Success) = No Error ; - 3 ($_IEStatus_InvalidDataType) = Invalid Data Type ; - 4 ($_IEStatus_InvalidObjectType) = Invalid Object Type ; - 5 ($_IEStatus_InvalidValue) = Invalid Value ; - 7 ($_IEStatus_NoMatch) = No Match ; @extended - Contains invalid parameter number ; Author ........: Dale Hohm ; =============================================================================================================================== Func _IEFormElementOptionSelect(ByRef $o_object, $s_string, $f_select = 1, $s_mode = "byValue", $f_fireEvent = 1) If Not IsObj($o_object) Then __IEErrorNotify("Error", "_IEFormElementOptionSelect", "$_IEStatus_InvalidDataType") Return SetError($_IEStatus_InvalidDataType, 1, 0) EndIf ; If Not __IEIsObjType($o_object, "formselectelement") Then __IEErrorNotify("Error", "_IEFormElementOptionSelect", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf ; Local $oItem, $oItems = $o_object.options, $iNumItems = $o_object.options.length, $f_isMultiple = $o_object.multiple Switch $s_mode Case "byValue" For $oItem In $oItems If $oItem.value = $s_string Then Switch $f_select Case -1 Return SetError($_IEStatus_Success, 0, $oItem.selected) Case 0 If Not $f_isMultiple Then __IEErrorNotify("Error", "_IEFormElementOptionSelect", "$_IEStatus_InvalidValue", _ "$f_select=0 only valid for type=select multiple") SetError($_IEStatus_InvalidValue, 3) EndIf If $oItem.selected Then $oItem.selected = False If $f_fireEvent Then $o_object.fireEvent("onChange") $o_object.fireEvent("OnClick") EndIf EndIf Return SetError($_IEStatus_Success, 0, 1) Case 1 If Not $oItem.selected Then $oItem.selected = True If $f_fireEvent Then $o_object.fireEvent("onChange") $o_object.fireEvent("OnClick") EndIf EndIf Return SetError($_IEStatus_Success, 0, 1) Case Else __IEErrorNotify("Error", "_IEFormElementOptionSelect", "$_IEStatus_InvalidValue", "Invalid $f_select value") Return SetError($_IEStatus_InvalidValue, 3, 0) EndSwitch __IEErrorNotify("Warning", "_IEFormElementOptionSelect", "$_IEStatus_NoMatch", "Value not matched") Return SetError($_IEStatus_NoMatch, 2, 0) EndIf Next Case "byText" For $oItem In $oItems If String($oItem.text) = $s_string Then Switch $f_select Case -1 Return SetError($_IEStatus_Success, 0, $oItem.selected) Case 0 If Not $f_isMultiple Then __IEErrorNotify("Error", "_IEFormElementOptionSelect", "$_IEStatus_InvalidValue", _ "$f_select=0 only valid for type=select multiple") SetError($_IEStatus_InvalidValue, 3) EndIf If $oItem.selected Then $oItem.selected = False If $f_fireEvent Then $o_object.fireEvent("onChange") $o_object.fireEvent("OnClick") EndIf EndIf Return SetError($_IEStatus_Success, 0, 1) Case 1 If Not $oItem.selected Then $oItem.selected = True If $f_fireEvent Then $o_object.fireEvent("onChange") $o_object.fireEvent("OnClick") EndIf EndIf Return SetError($_IEStatus_Success, 0, 1) Case Else __IEErrorNotify("Error", "_IEFormElementOptionSelect", "$_IEStatus_InvalidValue", "Invalid $f_select value") Return SetError($_IEStatus_InvalidValue, 3, 0) EndSwitch __IEErrorNotify("Warning", "_IEFormElementOptionSelect", "$_IEStatus_NoMatch", "Text not matched") Return SetError($_IEStatus_NoMatch, 2, 0) EndIf Next Case "byIndex" Local $i_index = Number($s_string) If $i_index < 0 Or $i_index >= $iNumItems Then __IEErrorNotify("Error", "_IEFormElementOptionSelect", "$_IEStatus_InvalidValue", "Invalid index value, " & $i_index) Return SetError($_IEStatus_InvalidValue, 2, 0) EndIf $oItem = $oItems.item($i_index) Switch $f_select Case -1 Return SetError($_IEStatus_Success, 0, $oItems.item($i_index).selected) Case 0 If Not $f_isMultiple Then __IEErrorNotify("Error", "_IEFormElementOptionSelect", "$_IEStatus_InvalidValue", _ "$f_select=0 only valid for type=select multiple") SetError($_IEStatus_InvalidValue, 3) EndIf If $oItem.selected Then $oItems.item($i_index).selected = False If $f_fireEvent Then $o_object.fireEvent("onChange") $o_object.fireEvent("OnClick") EndIf EndIf Return SetError($_IEStatus_Success, 0, 1) Case 1 If Not $oItem.selected Then $oItems.item($i_index).selected = True If $f_fireEvent Then $o_object.fireEvent("onChange") $o_object.fireEvent("OnClick") EndIf EndIf Return SetError($_IEStatus_Success, 0, 1) Case Else __IEErrorNotify("Error", "_IEFormElementOptionSelect", "$_IEStatus_InvalidValue", "Invalid $f_select value") Return SetError($_IEStatus_InvalidValue, 3, 0) EndSwitch Case Else __IEErrorNotify("Error", "_IEFormElementOptionSelect", "$_IEStatus_InvalidValue", "Invalid Mode") Return SetError($_IEStatus_InvalidValue, 4, 0) EndSwitch EndFunc ;==>_IEFormElementOptionSelect ; #FUNCTION# ==================================================================================================================== ; Name...........: _IEFormElementCheckBoxSelect ; Description ...: Set the value of a specified form element ; Parameters ....: $o_object - Object variable of an InternetExplorer.Application, Form object ; $s_string - Value used to match element - treatment based on $s_mode ; $s_name - Optional: Name or Id of checkbox(es) ; $f_select - Optional: specifies whether element should be checked or unchecked ; -1 = Return checked state ; 0 = Uncheck the element ; 1 = (Default) Check the element ; $s_mode - Optional: specifies search mode ; byValue = (Default) value of the checkbox you wish to select ; byIndex = 0-based index of checkbox you wish to select ; $f_fireEvent- Optional: specifies whether to fire an OnChange event after changing value ; 0 = do not fire OnChange event after setting value ; 1 = (Default) fire OnChange event after setting value ; Return values .: On Success - If $f_select = -1, returns the current checked state, else returns 1 ; On Failure - Returns 0 and sets @error ; @error - 0 ($_IEStatus_Success) = No Error ; - 3 ($_IEStatus_InvalidDataType) = Invalid Data Type ; - 4 ($_IEStatus_InvalidObjectType) = Invalid Object Type ; - 5 ($_IEStatus_InvalidValue) = Invalid Value ; - 7 ($_IEStatus_NoMatch) = No Match ; @extended - Contains invalid parameter number ; Author ........: Dale Hohm ; =============================================================================================================================== Func _IEFormElementCheckBoxSelect(ByRef $o_object, $s_string, $s_Name = "", $f_select = 1, $s_mode = "byValue", $f_fireEvent = 1) If Not IsObj($o_object) Then __IEErrorNotify("Error", "_IEFormElementCheckBoxSelect", "$_IEStatus_InvalidDataType") Return SetError($_IEStatus_InvalidDataType, 1, 0) EndIf ; If Not __IEIsObjType($o_object, "form") Then __IEErrorNotify("Error", "_IEFormElementCheckBoxSelect", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf ; $s_string = String($s_string) $s_Name = String($s_Name) Local $oItems If $s_Name = "" Then $oItems = _IETagNameGetCollection($o_object, "input") Else $oItems = Execute("$o_object.elements('" & $s_Name & "')") EndIf If Not IsObj($oItems) Then __IEErrorNotify("Warning", "_IEFormElementCheckBoxSelect", "$_IEStatus_NoMatch") Return SetError($_IEStatus_NoMatch, 3, 0) EndIf Local $oItem, $f_found = False Switch $s_mode Case "byValue" If __IEIsObjType($oItems, "forminputelement") Then $oItem = $oItems If String($oItem.type) = "checkbox" And String($oItem.value) = $s_string Then $f_found = True Else For $oItem In $oItems If String($oItem.type) = "checkbox" And String($oItem.value) = $s_string Then $f_found = True ExitLoop EndIf Next EndIf Case "byIndex" If __IEIsObjType($oItems, "forminputelement") Then $oItem = $oItems If String($oItem.type) = "checkbox" And Number($s_string) = 0 Then $f_found = True Else Local $iCount = 0 For $oItem In $oItems If String($oItem.type) = "checkbox" And Number($s_string) = $iCount Then $f_found = True ExitLoop Else If String($oItem.type) = "checkbox" Then $iCount += 1 EndIf Next EndIf Case Else __IEErrorNotify("Error", "_IEFormElementCheckBoxSelect", "$_IEStatus_InvalidValue", "Invalid Mode") Return SetError($_IEStatus_InvalidValue, 5, 0) EndSwitch If Not $f_found Then __IEErrorNotify("Warning", "_IEFormElementCheckBoxSelect", "$_IEStatus_NoMatch") Return SetError($_IEStatus_NoMatch, 2, 0) EndIf Switch $f_select Case -1 Return SetError($_IEStatus_Success, 0, $oItem.checked) Case 0 If $oItem.checked Then $oItem.checked = False If $f_fireEvent Then $oItem.fireEvent("onChange") $oItem.fireEvent("OnClick") EndIf EndIf Return SetError($_IEStatus_Success, 0, 1) Case 1 If Not $oItem.checked Then $oItem.checked = True If $f_fireEvent Then $oItem.fireEvent("onChange") $oItem.fireEvent("OnClick") EndIf EndIf Return SetError($_IEStatus_Success, 0, 1) Case Else __IEErrorNotify("Error", "_IEFormElementCheckBoxSelect", "$_IEStatus_InvalidValue", "Invalid $f_select value") Return SetError($_IEStatus_InvalidValue, 3, 0) EndSwitch EndFunc ;==>_IEFormElementCheckBoxSelect ; #FUNCTION# ==================================================================================================================== ; Name...........: _IEFormElementRadioSelect ; Description ...: Set the value of a specified form element ; Parameters ....: $o_object - Object variable of an InternetExplorer.Application, Form object ; $s_string - Value used to match element - treatment based on $s_mode ; $s_name - Name or Id of Radio Group (required) ; $f_select - Optional: specifies whether element should be selected or deselected ; -1 = Return selected state ; 0 = Deselect the element ; 1 = (Default) Select the element ; $s_mode - Optional: specifies search mode ; byValue = (Default) value of the radio you wish to select ; byIndex = 0-based index of radio you wish to select ; $f_fireEvent- Optional: specifies whether to fire an OnChange event after changing value ; 0 = do not fire OnChange event after setting value ; 1 = (Default) fire OnChange event after setting value ; Return values .: On Success - If $f_select = -1, returns the current selected state, else returns 1 ; On Failure - Returns 0 and sets @error ; @error - 0 ($_IEStatus_Success) = No Error ; - 3 ($_IEStatus_InvalidDataType) = Invalid Data Type ; - 4 ($_IEStatus_InvalidObjectType) = Invalid Object Type ; - 5 ($_IEStatus_InvalidValue) = Invalid Value ; - 7 ($_IEStatus_NoMatch) = No Match ; @extended - Contains invalid parameter number ; Author ........: Dale Hohm ; =============================================================================================================================== Func _IEFormElementRadioSelect(ByRef $o_object, $s_string, $s_Name, $f_select = 1, $s_mode = "byValue", $f_fireEvent = 1) If Not IsObj($o_object) Then __IEErrorNotify("Error", "_IEFormElementRadioSelect", "$_IEStatus_InvalidDataType") Return SetError($_IEStatus_InvalidDataType, 1, 0) EndIf ; If Not __IEIsObjType($o_object, "form") Then __IEErrorNotify("Error", "_IEFormElementRadioSelect", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf ; $s_string = String($s_string) $s_Name = String($s_Name) Local $oItems = Execute("$o_object.elements('" & $s_Name & "')") If Not IsObj($oItems) Then __IEErrorNotify("Warning", "_IEFormElementRadioSelect", "$_IEStatus_NoMatch") Return SetError($_IEStatus_NoMatch, 3, 0) EndIf Local $oItem, $f_found = False Switch $s_mode Case "byValue" If __IEIsObjType($oItems, "forminputelement") Then $oItem = $oItems If String($oItem.type) = "radio" And String($oItem.value) = $s_string Then $f_found = True Else For $oItem In $oItems If String($oItem.type) = "radio" And String($oItem.value) = $s_string Then $f_found = True ExitLoop EndIf Next EndIf Case "byIndex" If __IEIsObjType($oItems, "forminputelement") Then $oItem = $oItems If String($oItem.type) = "radio" And Number($s_string) = 0 Then $f_found = True Else Local $iCount = 0 For $oItem In $oItems If String($oItem.type) = "radio" And Number($s_string) = $iCount Then $f_found = True ExitLoop Else $iCount += 1 EndIf Next EndIf Case Else __IEErrorNotify("Error", "_IEFormElementRadioSelect", "$_IEStatus_InvalidValue", "Invalid Mode") Return SetError($_IEStatus_InvalidValue, 5, 0) EndSwitch If Not $f_found Then __IEErrorNotify("Warning", "_IEFormElementRadioSelect", "$_IEStatus_NoMatch") Return SetError($_IEStatus_NoMatch, 2, 0) EndIf Switch $f_select Case -1 Return SetError($_IEStatus_Success, 0, $oItem.checked) Case 0 If $oItem.checked Then $oItem.checked = False If $f_fireEvent Then $oItem.fireEvent("onChange") $oItem.fireEvent("OnClick") EndIf EndIf Return SetError($_IEStatus_Success, 0, 1) Case 1 If Not $oItem.checked Then $oItem.checked = True If $f_fireEvent Then $oItem.fireEvent("onChange") $oItem.fireEvent("OnClick") EndIf EndIf Return SetError($_IEStatus_Success, 0, 1) Case Else __IEErrorNotify("Error", "_IEFormElementRadioSelect", "$_IEStatus_InvalidValue", "$f_select value invalid") Return SetError($_IEStatus_InvalidValue, 4, 0) EndSwitch EndFunc ;==>_IEFormElementRadioSelect ; #FUNCTION# ==================================================================================================================== ; Name...........: _IEFormImageClick ; Description ...: Simulate a mouse click on an . Match by sub-string match of alt text, name or src ; Parameters ....: $o_object - Object variable of any DOM element (will be converted to the associated document object) ; $s_linkText - Value used to match element - treatment based on $s_mode ; $s_mode - Optional: specifies search mode ; src = (Default) match the url of the image ; name = match the name of the image ; alt = match the alternate text of the image ; $i_index - Optional: If the img text occurs more than once, specifies which instance ; you want to click by 0-based index ; $f_wait - Optional: specifies whether to wait for page to load before returning ; 0 = Return immediately, not waiting for page to load ; 1 = (Default) Wait for page load to complete before returning ; Return values .: On Success - Returns -1 ; On Failure - Returns 0 and sets @error ; @error - 0 ($_IEStatus_Success) = No Error ; - 1 ($_IEStatus_GeneralError) = General Error ; - 3 ($_IEStatus_InvalidDataType) = Invalid Data Type ; - 4 ($_IEStatus_InvalidObjectType) = Invalid Object Type ; - 5 ($_IEStatus_InvalidValue) = Invalid Value ; - 6 ($_IEStatus_LoadWaitTimeout) = Load Wait Timeout ; - 7 ($_IEStatus_NoMatch) = No Match ; - 8 ($_IEStatus_AccessIsDenied) = Access Is Denied ; - 9 ($_IEStatus_ClientDisconnected) = Client Disconnected ; @extended - Contains invalid parameter number ; Author ........: Dale Hohm ; =============================================================================================================================== Func _IEFormImageClick(ByRef $o_object, $s_linkText, $s_mode = "src", $i_index = 0, $f_wait = 1) If Not IsObj($o_object) Then __IEErrorNotify("Error", "_IEFormImageClick", "$_IEStatus_InvalidDataType") Return SetError($_IEStatus_InvalidDataType, 1, 0) EndIf ; Local $linktext, $found = 0 Local $oTemp = _IEDocGetObj($o_object) Local $imgs = _IETagNameGetCollection($oTemp, "input") $s_mode = StringLower($s_mode) $i_index = Number($i_index) For $img In $imgs If String($img.type) = "image" Then Select Case $s_mode = "alt" $linktext = $img.alt Case $s_mode = "name" $linktext = $img.name Case $s_mode = "src" $linktext = $img.src Case Else __IEErrorNotify("Error", "_IEFormImageClick", "$_IEStatus_InvalidValue", "Invalid mode: " & $s_mode) Return SetError($_IEStatus_InvalidValue, 3, 0) EndSelect If StringInStr($linktext, $s_linkText) Then If ($found = $i_index) Then $img.click() If @error Then ; Trap COM error, report and return Local $s_error = @error, $s_function_name = "_IEFormImageClick" __IEErrorNotify("Error", $s_function_name, "$_IEStatus_COMError", $s_error) Return SetError($_IEStatus_ComError, $s_error, 0) EndIf If $f_wait Then _IELoadWait($o_object) Return SetError(@error, 0, -1) EndIf Return SetError($_IEStatus_Success, 0, -1) EndIf $found = $found + 1 EndIf EndIf Next __IEErrorNotify("Warning", "_IEFormImageClick", "$_IEStatus_NoMatch") Return SetError($_IEStatus_NoMatch, 2, 0) EndFunc ;==>_IEFormImageClick ; #FUNCTION# ==================================================================================================================== ; Name...........: _IEFormSubmit ; Description ...: Submit a specified Form ; Parameters ....: $o_object - Object variable of an InternetExplorer.Application, Form object ; $f_wait - Optional: specifies whether to wait for page to load before returning ; 0 = Return immediately, not waiting for page to load ; 1 = (Default) Wait for page load to complete before returning ; Return values .: On Success - Returns -1 ; On Failure - Returns 0 and sets @error ; @error - 0 ($_IEStatus_Success) = No Error ; - 1 ($_IEStatus_GeneralError) = General Error ; - 3 ($_IEStatus_InvalidDataType) = Invalid Data Type ; - 4 ($_IEStatus_InvalidObjectType) = Invalid Object Type ; - 6 ($_IEStatus_LoadWaitTimeout) = Load Wait Timeout ; - 8 ($_IEStatus_AccessIsDenied) = Access Is Denied ; - 9 ($_IEStatus_ClientDisconnected) = Client Disconnected ; @extended - Contains invalid parameter number ; Author ........: Dale Hohm ; =============================================================================================================================== Func _IEFormSubmit(ByRef $o_object, $f_wait = 1) If Not IsObj($o_object) Then __IEErrorNotify("Error", "_IEFormSubmit", "$_IEStatus_InvalidDataType") Return SetError($_IEStatus_InvalidDataType, 1, 0) EndIf ; If Not __IEIsObjType($o_object, "form") Then __IEErrorNotify("Error", "_IEFormSubmit", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf ; Local $o_window = $o_object.document.parentWindow $o_object.submit() If @error Then ; Trap COM error, report and return Local $s_error = @error, $s_function_name = "_IEFormSubmit" __IEErrorNotify("Error", $s_function_name, "$_IEStatus_COMError", $s_error) Return SetError($_IEStatus_ComError, $s_error, 0) EndIf If $f_wait Then _IELoadWait($o_window) Return SetError(@error, 0, -1) EndIf Return SetError($_IEStatus_Success, 0, -1) EndFunc ;==>_IEFormSubmit ; #FUNCTION# ==================================================================================================================== ; Name...........: _IEFormReset ; Description ...: Reset a specified Form ; Parameters ....: $o_object - Object variable of an InternetExplorer.Application, Form object ; Return values .: On Success - Returns 1 ; On Failure - Returns 0 and sets @error ; @error - 0 ($_IEStatus_Success) = No Error ; - 3 ($_IEStatus_InvalidDataType) = Invalid Data Type ; - 4 ($_IEStatus_InvalidObjectType) = Invalid Object Type ; @extended - Contains invalid parameter number ; Author ........: Dale Hohm ; =============================================================================================================================== Func _IEFormReset(ByRef $o_object) If Not IsObj($o_object) Then __IEErrorNotify("Error", "_IEFormReset", "$_IEStatus_InvalidDataType") Return SetError($_IEStatus_InvalidDataType, 1, 0) EndIf ; If Not __IEIsObjType($o_object, "form") Then __IEErrorNotify("Error", "_IEFormReset", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf ; $o_object.reset() If @error Then ; Trap COM error, report and return Local $s_error = @error, $s_function_name = "_IEFormReset" __IEErrorNotify("Error", $s_function_name, "$_IEStatus_COMError", $s_error) Return SetError($_IEStatus_ComError, $s_error, 0) EndIf Return SetError($_IEStatus_Success, 0, 1) EndFunc ;==>_IEFormReset #endregion Form functions #region Table functions ; #FUNCTION# ==================================================================================================================== ; Name...........: _IETableGetCollection ; Description ...: Returns a collection object variable representing all the tables in a document ; Parameters ....: $o_object - Object variable of an InternetExplorer.Application, Window or Frame object ; $i_index - Optional: specifies whether to return a collection or indexed instance ; - 0 or positive integer returns an indexed instance ; - -1 = (Default) returns a collection ; Return values .: On Success - Returns an object collection of all tables in the document, @extended = table count ; On Failure - Returns 0 and sets @error ; @error - 0 ($_IEStatus_Success) = No Error ; - 3 ($_IEStatus_InvalidDataType) = Invalid Data Type ; - 5 ($_IEStatus_InvalidValue) = Invalid Value ; - 7 ($_IEStatus_NoMatch) = No Match ; @extended - Contains invalid parameter number ; Author ........: Dale Hohm ; =============================================================================================================================== Func _IETableGetCollection(ByRef $o_object, $i_index = -1) If Not IsObj($o_object) Then __IEErrorNotify("Error", "_IETableGetCollection", "$_IEStatus_InvalidDataType") Return SetError($_IEStatus_InvalidDataType, 1, 0) EndIf ; $i_index = Number($i_index) Select Case $i_index = -1 Return SetError($_IEStatus_Success, $o_object.document.GetElementsByTagName("table").length, _ $o_object.document.GetElementsByTagName("table")) Case $i_index > -1 And $i_index < $o_object.document.GetElementsByTagName("table").length Return SetError($_IEStatus_Success, $o_object.document.GetElementsByTagName("table").length, _ $o_object.document.GetElementsByTagName("table").item($i_index)) Case $i_index < -1 __IEErrorNotify("Error", "_IETableGetCollection", "$_IEStatus_InvalidValue", "$i_index < -1") Return SetError($_IEStatus_InvalidValue, 2, 0) Case Else __IEErrorNotify("Warning", "_IETableGetCollection", "$_IEStatus_NoMatch") Return SetError($_IEStatus_NoMatch, 1, 0) EndSelect EndFunc ;==>_IETableGetCollection ; #FUNCTION# ==================================================================================================================== ; Name...........: _IETableWriteToArray ; Description ...: Reads the contents of a Table into an array ; Parameters ....: $o_object - Object variable of an InternetExplorer.Application, Table object ; $f_transpose- Boolean value. If True, swap rows and columns in output array ; Return values .: On Success - Returns a 2-dimensional array containing the contents of the Table ; On Failure - Returns 0 and sets @error ; @error - 0 ($_IEStatus_Success) = No Error ; - 3 ($_IEStatus_InvalidDataType) = Invalid Data Type ; - 4 ($_IEStatus_InvalidObjectType) = Invalid Object Type ; @extended - Contains invalid parameter number ; Author ........: Dale Hohm ; =============================================================================================================================== Func _IETableWriteToArray(ByRef $o_object, $f_transpose = False) If Not IsObj($o_object) Then __IEErrorNotify("Error", "_IETableWriteToArray", "$_IEStatus_InvalidDataType") Return SetError($_IEStatus_InvalidDataType, 1, 0) EndIf ; If Not __IEIsObjType($o_object, "table") Then __IEErrorNotify("Error", "_IETableWriteToArray", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf ; Local $i_cols = 0, $tds, $i_col Local $trs = $o_object.rows For $tr In $trs $tds = $tr.cells $i_col = 0 For $td In $tds $i_col = $i_col + $td.colSpan Next If $i_col > $i_cols Then $i_cols = $i_col Next Local $i_rows = $trs.length Local $a_TableCells[$i_cols][$i_rows] Local $col, $row = 0 For $tr In $trs $tds = $tr.cells $col = 0 For $td In $tds $a_TableCells[$col][$row] = String($td.innerText) If @error Then ; Trap COM error, report and return Local $s_error = @error, $s_function_name = "_IETableWriteToArray" __IEErrorNotify("Error", $s_function_name, "$_IEStatus_COMError", $s_error) Return SetError($_IEStatus_ComError, $s_error, 0) EndIf $col = $col + $td.colSpan Next $row = $row + 1 Next If $f_transpose Then Local $i_d1 = UBound($a_TableCells, 1), $i_d2 = UBound($a_TableCells, 2), $aTmp[$i_d2][$i_d1] For $i = 0 To $i_d2 - 1 For $j = 0 To $i_d1 - 1 $aTmp[$i][$j] = $a_TableCells[$j][$i] Next Next $a_TableCells = $aTmp EndIf Return SetError($_IEStatus_Success, 0, $a_TableCells) EndFunc ;==>_IETableWriteToArray #endregion Table functions #region Read/Write functions ; #FUNCTION# ==================================================================================================================== ; Name...........: _IEBodyReadHTML ; Description ...: Returns the HTML inside the
tag of the document ; Parameters ....: $o_object - Object variable of an InternetExplorer.Application, Window or Frame object ; Return values .: On Success - Returns HTML included in the of the docuement ; On Failure - Returns 0 and sets @error ; @error - 0 ($_IEStatus_Success) = No Error ; - 3 ($_IEStatus_InvalidDataType) = Invalid Data Type ; @extended - Contains invalid parameter number ; Author ........: Dale Hohm ; =============================================================================================================================== Func _IEBodyReadHTML(ByRef $o_object) If Not IsObj($o_object) Then __IEErrorNotify("Error", "_IEBodyReadHTML", "$_IEStatus_InvalidDataType") Return SetError($_IEStatus_InvalidDataType, 1, 0) EndIf ; Return SetError($_IEStatus_Success, 0, $o_object.document.body.innerHTML) EndFunc ;==>_IEBodyReadHTML ; #FUNCTION# ==================================================================================================================== ; Name...........: _IEBodyReadText ; Description ...: Returns the Text inside the tag of the document ; Parameters ....: $o_object - Object variable of an InternetExplorer.Application, Window or Frame object ; Return values .: On Success - Returns the Text included in the of the docuement ; On Failure - Returns 0 and sets @error ; @error - 0 ($_IEStatus_Success) = No Error ; - 3 ($_IEStatus_InvalidDataType) = Invalid Data Type ; @extended - Contains invalid parameter number ; Author ........: Dale Hohm ; =============================================================================================================================== Func _IEBodyReadText(ByRef $o_object) If Not IsObj($o_object) Then __IEErrorNotify("Error", "_IEBodyReadText", "$_IEStatus_InvalidDataType") Return SetError($_IEStatus_InvalidDataType, 1, 0) EndIf If Not __IEIsObjType($o_object, "browserdom") Then __IEErrorNotify("Error", "_IEBodyReadText", "$_IEStatus_InvalidObjectType", "Expected document element") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf ; Return SetError($_IEStatus_Success, 0, $o_object.document.body.innerText) EndFunc ;==>_IEBodyReadText ; #FUNCTION# ==================================================================================================================== ; Name...........: _IEBodyWriteHTML ; Description ...: Replaces the HTML inside the tag of the document ; Parameters ....: $o_object - Object variable of an InternetExplorer.Application, Window or Frame object ; $s_html - The HTML string to write to the document ; Return values .: On Success - Returns -1 ; On Failure - Returns 0 and sets @error ; @error - 0 ($_IEStatus_Success) = No Error ; - 1 ($_IEStatus_GeneralError) = General Error ; - 3 ($_IEStatus_InvalidDataType) = Invalid Data Type ; - 4 ($_IEStatus_InvalidObjectType) = Invalid Object Type ; - 6 ($_IEStatus_LoadWaitTimeout) = Load Wait Timeout ; - 8 ($_IEStatus_AccessIsDenied) = Access Is Denied ; - 9 ($_IEStatus_ClientDisconnected) = Client Disconnected ; @extended - Contains invalid parameter number ; Author ........: Dale Hohm ; =============================================================================================================================== Func _IEBodyWriteHTML(ByRef $o_object, $s_html) If Not IsObj($o_object) Then __IEErrorNotify("Error", "_IEBodyWriteHTML", "$_IEStatus_InvalidDataType") Return SetError($_IEStatus_InvalidDataType, 1, 0) EndIf If Not __IEIsObjType($o_object, "browserdom") Then __IEErrorNotify("Error", "_IEBodyWriteHTML", "$_IEStatus_InvalidObjectType", "Expected document element") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf ; $o_object.document.body.innerHTML = $s_html If @error Then ; Trap COM error, report and return Local $s_error = @error, $s_function_name = "_IEBodyWriteHTML" __IEErrorNotify("Error", $s_function_name, "$_IEStatus_COMError", $s_error) Return SetError($_IEStatus_ComError, $s_error, 0) EndIf Local $oTemp = $o_object.document _IELoadWait($oTemp) Return SetError(@error, 0, -1) EndFunc ;==>_IEBodyWriteHTML ; #FUNCTION# ==================================================================================================================== ; Name...........: _IEDocReadHTML ; Description ...: Returns the full HTML source of a document ; Parameters ....: $o_object - Object variable of an InternetExplorer.Application, Window or Frame object ; Return values .: On Success - Returns the HTML included in the of the docuement, including the and tags ; On Failure - Returns 0 and sets @error ; @error - 0 ($_IEStatus_Success) = No Error ; - 3 ($_IEStatus_InvalidDataType) = Invalid Data Type ; @extended - Contains invalid parameter number ; Author ........: Dale Hohm ; =============================================================================================================================== Func _IEDocReadHTML(ByRef $o_object) If Not IsObj($o_object) Then __IEErrorNotify("Error", "_IEDocReadHTML", "$_IEStatus_InvalidDataType") Return SetError($_IEStatus_InvalidDataType, 1, 0) EndIf If Not __IEIsObjType($o_object, "browserdom") Then __IEErrorNotify("Error", "_IEDocReadHTML", "$_IEStatus_InvalidObjectType", "Expected document element") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf ; Return SetError($_IEStatus_Success, 0, $o_object.document.documentElement.outerHTML) EndFunc ;==>_IEDocReadHTML ; #FUNCTION# ==================================================================================================================== ; Name...........: _IEDocWriteHTML ; Description ...: Replaces the HTML for the entire document ; Parameters ....: $o_object - Object variable of an InternetExplorer.Application, Window or Frame object ; $s_html - The HTML string to write to the document ; Return values .: On Success - Returns -1 ; On Failure - Returns 0 and sets @error ; @error - 0 ($_IEStatus_Success) = No Error ; - 1 ($_IEStatus_GeneralError) = General Error ; - 3 ($_IEStatus_InvalidDataType) = Invalid Data Type ; - 4 ($_IEStatus_InvalidObjectType) = Invalid Object Type ; - 6 ($_IEStatus_LoadWaitTimeout) = Load Wait Timeout ; - 8 ($_IEStatus_AccessIsDenied) = Access Is Denied ; - 9 ($_IEStatus_ClientDisconnected) = Client Disconnected ; @extended - Contains invalid parameter number ; Author ........: Dale Hohm ; =============================================================================================================================== Func _IEDocWriteHTML(ByRef $o_object, $s_html) If Not IsObj($o_object) Then __IEErrorNotify("Error", "_IEDocWriteHTML", "$_IEStatus_InvalidDataType") Return SetError($_IEStatus_InvalidDataType, 1, 0) EndIf If Not __IEIsObjType($o_object, "browserdom") Then __IEErrorNotify("Error", "_IEDocWriteHTML", "$_IEStatus_InvalidObjectType", "Expected document element") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf ; $o_object.document.Write($s_html) $o_object.document.close() Local $oTemp = $o_object.document If @error Then ; Trap COM error, report and return Local $s_error = @error, $s_function_name = "_IEDocWriteHTML" __IEErrorNotify("Error", $s_function_name, "$_IEStatus_COMError", $s_error) Return SetError($_IEStatus_ComError, $s_error, 0) EndIf _IELoadWait($oTemp) Return SetError(@error, 0, -1) EndFunc ;==>_IEDocWriteHTML ; #FUNCTION# ==================================================================================================================== ; Name...........: _IEDocInsertText ; Description ...: Inserts text adjacent to a specified document element ; Parameters ....: $o_object - Object variable of a document element ; $s_string - String containing text to insert ; $s_where - String value signifying where to insert relative to $o_object ; - BeforeBegin = before start tag of specified object ; - AfterBegin = after start tag of specified object ; - BeforeEnd = (Default) before end tag of specified object ; - AfterEnd = after end tag of specified object ; Return values .: On Success - Returns 1 ; On Failure - Returns 0 and sets @error ; @error - 0 ($_IEStatus_Success) = No Error ; - 3 ($_IEStatus_InvalidDataType) = Invalid Data Type ; - 4 ($_IEStatus_InvalidObjectType) = Invalid Object Type ; - 5 ($_IEStatus_InvalidValue) = Invalid Value ; @extended - Contains invalid parameter number ; Author ........: Dale Hohm ; =============================================================================================================================== Func _IEDocInsertText(ByRef $o_object, $s_string, $s_where = "beforeend") If Not IsObj($o_object) Then __IEErrorNotify("Error", "_IEDocInsertText", "$_IEStatus_InvalidDataType") Return SetError($_IEStatus_InvalidDataType, 1, 0) EndIf If Not __IEIsObjType($o_object, "browserdom") Or __IEIsObjType($o_object, "documentcontainer") Or __IEIsObjType($o_object, "document") Then __IEErrorNotify("Error", "_IEDocInsertText", "$_IEStatus_InvalidObjectType", "Expected document element") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf $s_where = StringLower($s_where) Select Case $s_where = "beforebegin" $o_object.insertAdjacentText($s_where, $s_string) Case $s_where = "afterbegin" $o_object.insertAdjacentText($s_where, $s_string) Case $s_where = "beforeend" $o_object.insertAdjacentText($s_where, $s_string) Case $s_where = "afterend" $o_object.insertAdjacentText($s_where, $s_string) Case Else ; Unsupported Where __IEErrorNotify("Error", "_IEDocInsertText", "$_IEStatus_InvalidValue", "Invalid where value") Return SetError($_IEStatus_InvalidValue, 3, 0) EndSelect If @error Then ; Trap COM error, report and return Local $s_error = @error, $s_function_name = "_IEDocInsertText" __IEErrorNotify("Error", $s_function_name, "$_IEStatus_COMError", $s_error) Return SetError($_IEStatus_ComError, $s_error, 0) EndIf Return SetError($_IEStatus_Success, 0, 1) EndFunc ;==>_IEDocInsertText ; #FUNCTION# ==================================================================================================================== ; Name...........: _IEDocInsertHTML ; Description ...: Inserts HTML adjacent to a specified document element ; Parameters ....: $o_object - Object variable of a document element ; $s_string - String containing text to insert ; $s_where - String value signifying where to insert relative to $o_object ; - BeforeBegin = before start tag of specified object ; - AfterBegin = after start tag of specified object ; - BeforeEnd = (Default) before end tag of specified object ; - AfterEnd = after end tag of specified object ; Return values .: On Success - Returns 1 ; On Failure - Returns 0 and sets @error ; @error - 0 ($_IEStatus_Success) = No Error ; - 3 ($_IEStatus_InvalidDataType) = Invalid Data Type ; - 4 ($_IEStatus_InvalidObjectType) = Invalid Object Type ; - 5 ($_IEStatus_InvalidValue) = Invalid Value ; @extended - Contains invalid parameter number ; Author ........: Dale Hohm ; =============================================================================================================================== Func _IEDocInsertHTML(ByRef $o_object, $s_string, $s_where = "beforeend") If Not IsObj($o_object) Then __IEErrorNotify("Error", "_IEDocInsertHTML", "$_IEStatus_InvalidDataType") Return SetError($_IEStatus_InvalidDataType, 1, 0) EndIf If Not __IEIsObjType($o_object, "browserdom") Or __IEIsObjType($o_object, "documentcontainer") Or __IEIsObjType($o_object, "document") Then __IEErrorNotify("Error", "_IEDocInsertHTML", "$_IEStatus_InvalidObjectType", "Expected document element") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf $s_where = StringLower($s_where) Select Case $s_where = "beforebegin" $o_object.insertAdjacentHTML($s_where, $s_string) Case $s_where = "afterbegin" $o_object.insertAdjacentHTML($s_where, $s_string) Case $s_where = "beforeend" $o_object.insertAdjacentHTML($s_where, $s_string) Case $s_where = "afterend" $o_object.insertAdjacentHTML($s_where, $s_string) Case Else ; Unsupported Where __IEErrorNotify("Error", "_IEDocInsertHTML", "$_IEStatus_InvalidValue", "Invalid where value") Return SetError($_IEStatus_InvalidValue, 3, 0) EndSelect If @error Then ; Trap COM error, report and return Local $s_error = @error, $s_function_name = "_IEDocInsertHTML" __IEErrorNotify("Error", $s_function_name, "$_IEStatus_COMError", $s_error) Return SetError($_IEStatus_ComError, $s_error, 0) EndIf Return SetError($_IEStatus_Success, 0, 1) EndFunc ;==>_IEDocInsertHTML ; #FUNCTION# ==================================================================================================================== ; Name...........: _IEHeadInsertEventScript ; Description ...: Inserts a Javascript into the Head of the document ; Parameters ....: $o_object - Object variable of an InternetExplorer.Application, Window or Frame object ; $s_htmlFor - The HTML element for event monitoring (e.g. "document" or an element ID) ; $s_event - The event to monitor (e.g. "onclick" or "oncontextmenu") ; $s_script - Javascript string to be executed ; Return values .: On Success - Returns 1 ; On Failure - Returns 0 and sets @error ; @error - 0 ($_IEStatus_Success) = No Error ; - 3 ($_IEStatus_InvalidDataType) = Invalid Data Type ; @extended - Contains invalid parameter number ; Author ........: Dale Hohm ; =============================================================================================================================== Func _IEHeadInsertEventScript(ByRef $o_object, $s_htmlFor, $s_event, $s_script) If Not IsObj($o_object) Then __IEErrorNotify("Error", "_IEHeadInsertEventScript", "$_IEStatus_InvalidDataType") Return SetError($_IEStatus_InvalidDataType, 1, 0) EndIf Local $o_head = $o_object.document.all.tags("HEAD").Item(0) Local $o_script = $o_object.document.createElement("script") With $o_script .defer = True .language = "jscript" .type = "text/javascript" .htmlFor = $s_htmlFor .event = $s_event .text = $s_script EndWith $o_head.appendChild($o_script) If @error Then ; Trap COM error, report and return Local $s_error = @error, $s_function_name = "_IEHeadInsertEventScript" __IEErrorNotify("Error", $s_function_name, "$_IEStatus_COMError", $s_error) Return SetError($_IEStatus_ComError, $s_error, 0) EndIf Return SetError($_IEStatus_Success, 0, 1) EndFunc ;==>_IEHeadInsertEventScript #endregion Read/Write functions #region Utility functions ; #FUNCTION# ==================================================================================================================== ; Name...........: _IEDocGetObj ; Description ...: Given any DOM object, returns a reference to the associated document object ; Parameters ....: $o_object - Object variable of an InternetExplorer.Application, Window or Frame object ; Return values .: On Success - Returns an object variable pointing to the Document object ; On Failure - Returns 0 and sets @error ; @error - 0 ($_IEStatus_Success) = No Error ; - 3 ($_IEStatus_InvalidDataType) = Invalid Data Type ; @extended - Contains invalid parameter number ; Author ........: Dale Hohm ; =============================================================================================================================== Func _IEDocGetObj(ByRef $o_object) If Not IsObj($o_object) Then __IEErrorNotify("Error", "_IEDocGetObj", "$_IEStatus_InvalidDataType") Return SetError($_IEStatus_InvalidDataType, 1, 0) EndIf ; Switch __IEIsObjType($o_object, "document") Case True Return SetError($_IEStatus_Success, 0, $o_object) Case False Return SetError($_IEStatus_Success, 0, $o_object.document) EndSwitch EndFunc ;==>_IEDocGetObj ; #FUNCTION# ==================================================================================================================== ; Name...........: _IETagNameGetCollection ; Description ...: Returns a collection object of all elements in the object with the specified TagName. ; Parameters ....: $o_object - Object variable of an InternetExplorer.Application, Window, Frame, iFrame or any object in the DOM ; $s_TagName - TagName of collection to return (e.g. IMG, TR etc.) ; $i_index - Optional: specifies whether to return a collection or indexed instance ; - 0 or positive integer returns an indexed instance ; - -1 = (Default) returns a collection ; Return values .: On Success - Returns an object variable containing the specified Tag collection, @extended = specified Tag count ; On Failure - Returns 0 and sets @error ; @error - 0 ($_IEStatus_Success) = No Error ; - 3 ($_IEStatus_InvalidDataType) = Invalid Data Type ; - 4 ($_IEStatus_InvalidObjectType) = Invalid Object Type ; - 5 ($_IEStatus_InvalidValue) = Invalid Value ; - 7 ($_IEStatus_NoMatch) = No Match ; @extended - Contains invalid parameter number ; Author ........: Dale Hohm ; =============================================================================================================================== Func _IETagNameGetCollection(ByRef $o_object, $s_TagName, $i_index = -1) If Not IsObj($o_object) Then __IEErrorNotify("Error", "_IETagNameGetCollection", "$_IEStatus_InvalidDataType") Return SetError($_IEStatus_InvalidDataType, 1, 0) EndIf ; If Not __IEIsObjType($o_object, "browserdom") Then __IEErrorNotify("Error", "_IETagNameGetCollection", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf Local $oTemp If __IEIsObjType($o_object, "documentcontainer") Then $oTemp = _IEDocGetObj($o_object) Else $oTemp = $o_object EndIf $i_index = Number($i_index) Select Case $i_index = -1 Return SetError($_IEStatus_Success, $oTemp.GetElementsByTagName($s_TagName).length, _ $oTemp.GetElementsByTagName($s_TagName)) Case $i_index > -1 And $i_index < $oTemp.GetElementsByTagName($s_TagName).length Return SetError($_IEStatus_Success, $oTemp.GetElementsByTagName($s_TagName).length, _ $oTemp.GetElementsByTagName($s_TagName).item($i_index)) Case $i_index < -1 __IEErrorNotify("Error", "_IETagNameGetCollection", "$_IEStatus_InvalidValue", "$i_index < -1") Return SetError($_IEStatus_InvalidValue, 3, 0) Case Else __IEErrorNotify("Error", "_IETagNameGetCollection", "$_IEStatus_NoMatch") Return SetError($_IEStatus_NoMatch, 0, 0) ; Could be caused by parameter 2, 3 or both EndSelect EndFunc ;==>_IETagNameGetCollection ; #FUNCTION# ==================================================================================================================== ; Name...........: _IETagNameAllGetCollection ; Description ...: Returns a collection object all elements in the document or document hierarchy in source order. ; Parameters ....: $o_object - Object variable of an InternetExplorer.Application, Window, Frame, iFrame or any object in the DOM ; $i_index - Optional: specifies whether to return a collection or indexed instance ; - 0 or positive integer returns an indexed instance ; - -1 = (Default) returns a collection ; Return values .: On Success - Returns an object variable containing the Tag collection, @extended = Tag count ; On Failure - Returns 0 and sets @error ; @error - 0 ($_IEStatus_Success) = No Error ; - 3 ($_IEStatus_InvalidDataType) = Invalid Data Type ; - 4 ($_IEStatus_InvalidObjectType) = Invalid Object Type ; - 5 ($_IEStatus_InvalidValue) = Invalid Value ; - 7 ($_IEStatus_NoMatch) = No Match ; @extended - Contains invalid parameter number ; Author ........: Dale Hohm ; =============================================================================================================================== Func _IETagNameAllGetCollection(ByRef $o_object, $i_index = -1) If Not IsObj($o_object) Then __IEErrorNotify("Error", "_IETagNameAllGetCollection", "$_IEStatus_InvalidDataType") Return SetError($_IEStatus_InvalidDataType, 1, 0) EndIf ; If Not __IEIsObjType($o_object, "browserdom") Then __IEErrorNotify("Error", "_IETagNameAllGetCollection", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf Local $oTemp If __IEIsObjType($o_object, "documentcontainer") Then $oTemp = _IEDocGetObj($o_object) Else $oTemp = $o_object EndIf $i_index = Number($i_index) Select Case $i_index = -1 Return SetError($_IEStatus_Success, $oTemp.all.length, $oTemp.all) Case $i_index > -1 And $i_index < $oTemp.all.length Return SetError($_IEStatus_Success, $oTemp.all.length, $oTemp.all.item($i_index)) Case $i_index < -1 __IEErrorNotify("Error", "_IETagNameAllGetCollection", "$_IEStatus_InvalidValue", "$i_index < -1") Return SetError($_IEStatus_InvalidValue, 2, 0) Case Else __IEErrorNotify("Error", "_IETagNameAllGetCollection", "$_IEStatus_NoMatch") Return SetError($_IEStatus_NoMatch, 1, 0) EndSelect EndFunc ;==>_IETagNameAllGetCollection ; #FUNCTION# ==================================================================================================================== ; Name...........: _IEGetObjByName ; Description ...: Returns an object variable by Id or name ; Parameters ....: $o_object - Object variable of an InternetExplorer.Application, Window or Frame object ; $s_Id - Specifies name or id of the object you wish to match ; $i_index - Optional: If Name of Id occurs more than once, specifies instance by 0-based index ; - 0 (Default) or positive integer returns an indexed instance ; - -1 returns a collection of the specified objects ; Return values .: On Success - Returns an object variable pointing to the specified Object, @extended = specified object count ; On Failure - Returns 0 and sets @error ; @error - 0 ($_IEStatus_Success) = No Error ; - 3 ($_IEStatus_InvalidDataType) = Invalid Data Type ; - 7 ($_IEStatus_NoMatch) = No Match ; @extended - Contains invalid parameter number ; Author ........: Dale Hohm ; =============================================================================================================================== Func _IEGetObjByName(ByRef $o_object, $s_Id, $i_index = 0) If Not IsObj($o_object) Then __IEErrorNotify("Error", "_IEGetObjByName", "$_IEStatus_InvalidDataType") Return SetError($_IEStatus_InvalidDataType, 1, 0) EndIf ; $i_index = Number($i_index) If $i_index = -1 Then Return SetError($_IEStatus_Success, $o_object.document.GetElementsByName($s_Id).length, _ $o_object.document.GetElementsByName($s_Id)) Else If IsObj($o_object.document.GetElementsByName($s_Id).item($i_index)) Then Return SetError($_IEStatus_Success, $o_object.document.GetElementsByName($s_Id).length, _ $o_object.document.GetElementsByName($s_Id).item($i_index)) Else __IEErrorNotify("Warning", "_IEGetObjByName", "$_IEStatus_NoMatch", "Name: " & $s_Id & ", Index: " & $i_index) Return SetError($_IEStatus_NoMatch, 0, 0) ; Could be caused by parameter 2, 3 or both EndIf EndIf EndFunc ;==>_IEGetObjByName ; #FUNCTION# ==================================================================================================================== ; Name...........: _IEGetObjById ; Description ...: Returns an object variable by Id or name ; Parameters ....: $o_object - Object variable of an InternetExplorer.Application, Window or Frame object ; $s_Id - Specifies id of the object you wish to match ; Return values .: On Success - Returns an object variable pointing to the specified Object ; On Failure - Returns 0 and sets @error ; @error - 0 ($_IEStatus_Success) = No Error ; - 3 ($_IEStatus_InvalidDataType) = Invalid Data Type ; - 7 ($_IEStatus_NoMatch) = No Match ; @extended - Contains invalid parameter number ; Author ........: Dale Hohm ; =============================================================================================================================== Func _IEGetObjById(ByRef $o_object, $s_Id) If Not IsObj($o_object) Then __IEErrorNotify("Error", "_IEGetObjById", "$_IEStatus_InvalidDataType") Return SetError($_IEStatus_InvalidDataType, 1, 0) EndIf ; If Not __IEIsObjType($o_object, "browserdom") Then __IEErrorNotify("Error", "_IEGetObById", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf ; If IsObj($o_object.document.getElementById($s_Id)) Then Return SetError($_IEStatus_Success, 0, $o_object.document.getElementById($s_Id)) Else __IEErrorNotify("Warning", "_IEGetObjById", "$_IEStatus_NoMatch", $s_Id) Return SetError($_IEStatus_NoMatch, 2, 0) EndIf EndFunc ;==>_IEGetObjById ; #FUNCTION# ==================================================================================================================== ; Name...........: _IEAction ; Description ...: Perform any of a set of simple actions on the Browser ; Parameters ....: $o_object - Object variable of an InternetExplorer.Application ; $s_action - Action selection ; Return values .: On Success - Returns 1 ; On Failure - Returns 0 and sets @error ; @error - 0 ($_IEStatus_Success) = No Error ; - 3 ($_IEStatus_InvalidDataType) = Invalid Data Type ; - 4 ($_IEStatus_InvalidObjectType) = Invalid Object Type ; - 5 ($_IEStatus_InvalidValue) = Invalid Value ; @extended - Contains invalid parameter number ; Author ........: Dale Hohm ; =============================================================================================================================== Func _IEAction(ByRef $o_object, $s_action) If Not IsObj($o_object) Then __IEErrorNotify("Error", "_IEAction", "$_IEStatus_InvalidDataType") Return SetError($_IEStatus_InvalidDataType, 1, 0) EndIf ; Local $s_error = @error, $s_function_name = "_IEAction" $s_action = StringLower($s_action) Select ; DOM objects Case $s_action = "click" If __IEIsObjType($o_object, "documentContainer") Then __IEErrorNotify("Error", "_IEAction", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf $o_object.Click() Case $s_action = "disable" If __IEIsObjType($o_object, "documentContainer") Then __IEErrorNotify("Error", "_IEAction", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf $o_object.disabled = True Case $s_action = "enable" If __IEIsObjType($o_object, "documentContainer") Then __IEErrorNotify("Error", "_IEAction", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf $o_object.disabled = False Case $s_action = "focus" If __IEIsObjType($o_object, "documentContainer") Then __IEErrorNotify("Error", "_IEAction", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf $o_object.Focus() Case $s_action = "scrollintoview" If __IEIsObjType($o_object, "documentContainer") Then __IEErrorNotify("Error", "_IEAction", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf $o_object.scrollIntoView() ; Browser Object Case $s_action = "copy" $o_object.document.execCommand("Copy") Case $s_action = "cut" $o_object.document.execCommand("Cut") Case $s_action = "paste" $o_object.document.execCommand("Paste") Case $s_action = "delete" $o_object.document.execCommand("Delete") Case $s_action = "saveas" $o_object.document.execCommand("SaveAs") Case $s_action = "refresh" $o_object.document.execCommand("Refresh") If @error Then ; Trap COM error, report and return __IEErrorNotify("Error", $s_function_name, "$_IEStatus_COMError", $s_error) Return SetError($_IEStatus_ComError, $s_error, 0) EndIf _IELoadWait($o_object) Case $s_action = "selectall" $o_object.document.execCommand("SelectAll") Case $s_action = "unselect" $o_object.document.execCommand("Unselect") Case $s_action = "print" $o_object.document.parentwindow.Print() Case $s_action = "printdefault" If Not __IEIsObjType($o_object, "browser") Then __IEErrorNotify("Error", "_IEAction", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf $o_object.execWB(6, 2) Case $s_action = "back" If Not __IEIsObjType($o_object, "documentContainer") Then __IEErrorNotify("Error", "_IEAction", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf $o_object.GoBack() Case $s_action = "blur" $o_object.Blur() Case $s_action = "forward" If Not __IEIsObjType($o_object, "documentContainer") Then __IEErrorNotify("Error", "_IEAction", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf $o_object.GoForward() Case $s_action = "home" If Not __IEIsObjType($o_object, "documentContainer") Then __IEErrorNotify("Error", "_IEAction", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf $o_object.GoHome() Case $s_action = "invisible" If Not __IEIsObjType($o_object, "browser") Then __IEErrorNotify("Error", "_IEAction", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf $o_object.visible = 0 Case $s_action = "visible" If Not __IEIsObjType($o_object, "browser") Then __IEErrorNotify("Error", "_IEAction", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf $o_object.visible = 1 Case $s_action = "search" If Not __IEIsObjType($o_object, "browser") Then __IEErrorNotify("Error", "_IEAction", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf $o_object.GoSearch() Case $s_action = "stop" If Not __IEIsObjType($o_object, "documentContainer") Then __IEErrorNotify("Error", "_IEAction", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf $o_object.Stop() Case $s_action = "quit" If Not __IEIsObjType($o_object, "browser") Then __IEErrorNotify("Error", "_IEAction", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf $o_object.Quit() If @error Then ; Trap COM error, report and return __IEErrorNotify("Error", $s_function_name, "$_IEStatus_COMError", $s_error) Return SetError($_IEStatus_ComError, $s_error, 0) EndIf $o_object = 0 Return SetError($_IEStatus_Success, 0, 1) Case Else ; Unsupported Action __IEErrorNotify("Error", "_IEAction", "$_IEStatus_InvalidValue", "Invalid Action") Return SetError($_IEStatus_InvalidValue, 2, 0) EndSelect If @error Then ; Trap COM error, report and return __IEErrorNotify("Error", $s_function_name, "$_IEStatus_COMError", $s_error) Return SetError($_IEStatus_ComError, $s_error, 0) EndIf Return SetError($_IEStatus_Success, 0, 1) EndFunc ;==>_IEAction ; #FUNCTION# ==================================================================================================================== ; Name...........: _IEPropertyGet ; Description ...: Returns a select property of the browser ; Parameters ....: $o_object - Object variable of an InternetExplorer.Application ; $s_property - Property selection ; Return values .: On Success - Value of selected Property ; On Failure - Returns 0 and sets @error ; @error - 0 ($_IEStatus_Success) = No Error ; - 3 ($_IEStatus_InvalidDataType) = Invalid Data Type ; - 4 ($_IEStatus_InvalidObjectType) = Invalid Object Type ; - 5 ($_IEStatus_InvalidValue) = Invalid Value ; @extended - Contains invalid parameter number ; Author ........: Dale Hohm ; =============================================================================================================================== Func _IEPropertyGet(ByRef $o_object, $s_property) If Not IsObj($o_object) Then __IEErrorNotify("Error", "_IEPropertyGet", "$_IEStatus_InvalidDataType") Return SetError($_IEStatus_InvalidDataType, 1, 0) EndIf If Not __IEIsObjType($o_object, "browserdom") Then __IEErrorNotify("Error", "_IEPropertyGet", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf ; Local $oTemp, $iTemp $s_property = StringLower($s_property) Select Case $s_property = "browserx" If __IEIsObjType($o_object, "browsercontainer") Or __IEIsObjType($o_object, "document") Then __IEErrorNotify("Error", "_IEPropertyGet", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf $oTemp = $o_object $iTemp = 0 While IsObj($oTemp) $iTemp += $oTemp.offsetLeft $oTemp = $oTemp.offsetParent WEnd Return SetError($_IEStatus_Success, 0, $iTemp) Case $s_property = "browsery" If __IEIsObjType($o_object, "browsercontainer") Or __IEIsObjType($o_object, "document") Then __IEErrorNotify("Error", "_IEPropertyGet", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf $oTemp = $o_object $iTemp = 0 While IsObj($oTemp) $iTemp += $oTemp.offsetTop $oTemp = $oTemp.offsetParent WEnd Return SetError($_IEStatus_Success, 0, $iTemp) Case $s_property = "screenx" If __IEIsObjType($o_object, "window") Or __IEIsObjType($o_object, "document") Then __IEErrorNotify("Error", "_IEPropertyGet", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf If __IEIsObjType($o_object, "browser") Then Return SetError($_IEStatus_Success, 0, $o_object.left()) Else $oTemp = $o_object $iTemp = 0 While IsObj($oTemp) $iTemp += $oTemp.offsetLeft $oTemp = $oTemp.offsetParent WEnd EndIf Return SetError($_IEStatus_Success, 0, _ $iTemp + $o_object.document.parentWindow.screenLeft) Case $s_property = "screeny" If __IEIsObjType($o_object, "window") Or __IEIsObjType($o_object, "document") Then __IEErrorNotify("Error", "_IEPropertyGet", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf If __IEIsObjType($o_object, "browser") Then Return SetError($_IEStatus_Success, 0, $o_object.top()) Else $oTemp = $o_object $iTemp = 0 While IsObj($oTemp) $iTemp += $oTemp.offsetTop $oTemp = $oTemp.offsetParent WEnd EndIf Return SetError($_IEStatus_Success, 0, _ $iTemp + $o_object.document.parentWindow.screenTop) Case $s_property = "height" If __IEIsObjType($o_object, "window") Or __IEIsObjType($o_object, "document") Then __IEErrorNotify("Error", "_IEPropertyGet", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf If __IEIsObjType($o_object, "browser") Then Return SetError($_IEStatus_Success, 0, $o_object.Height()) Else Return SetError($_IEStatus_Success, 0, $o_object.offsetHeight) EndIf Case $s_property = "width" If __IEIsObjType($o_object, "window") Or __IEIsObjType($o_object, "document") Then __IEErrorNotify("Error", "_IEPropertyGet", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf If __IEIsObjType($o_object, "browser") Then Return SetError($_IEStatus_Success, 0, $o_object.Width()) Else Return SetError($_IEStatus_Success, 0, $o_object.offsetWidth) EndIf Case $s_property = "isdisabled" Return SetError($_IEStatus_Success, 0, $o_object.isDisabled()) Case $s_property = "addressbar" If Not __IEIsObjType($o_object, "browser") Then __IEErrorNotify("Error", "_IEPropertyGet", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf Return SetError($_IEStatus_Success, 0, $o_object.AddressBar()) Case $s_property = "busy" If Not __IEIsObjType($o_object, "browser") Then __IEErrorNotify("Error", "_IEPropertyGet", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf Return SetError($_IEStatus_Success, 0, $o_object.Busy()) Case $s_property = "fullscreen" If Not __IEIsObjType($o_object, "browser") Then __IEErrorNotify("Error", "_IEPropertyGet", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf Return SetError($_IEStatus_Success, 0, $o_object.fullScreen()) Case $s_property = "hwnd" If Not __IEIsObjType($o_object, "browser") Then __IEErrorNotify("Error", "_IEPropertyGet", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf Return SetError($_IEStatus_Success, 0, HWnd($o_object.HWnd())) Case $s_property = "left" If Not __IEIsObjType($o_object, "browser") Then __IEErrorNotify("Error", "_IEPropertyGet", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf Return SetError($_IEStatus_Success, 0, $o_object.Left()) Case $s_property = "locationname" If Not __IEIsObjType($o_object, "browser") Then __IEErrorNotify("Error", "_IEPropertyGet", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf Return SetError($_IEStatus_Success, 0, $o_object.LocationName()) Case $s_property = "locationurl" If __IEIsObjType($o_object, "browser") Then Return SetError($_IEStatus_Success, 0, $o_object.locationURL()) EndIf If __IEIsObjType($o_object, "window") Then Return SetError($_IEStatus_Success, 0, $o_object.location.href()) EndIf If __IEIsObjType($o_object, "document") Then Return SetError($_IEStatus_Success, 0, $o_object.parentwindow.location.href()) EndIf Return SetError($_IEStatus_Success, 0, $o_object.document.parentwindow.location.href()) Case $s_property = "menubar" If Not __IEIsObjType($o_object, "browser") Then __IEErrorNotify("Error", "_IEPropertyGet", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf Return SetError($_IEStatus_Success, 0, $o_object.MenuBar()) Case $s_property = "offline" If Not __IEIsObjType($o_object, "browser") Then __IEErrorNotify("Error", "_IEPropertyGet", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf Return SetError($_IEStatus_Success, 0, $o_object.OffLine()) Case $s_property = "readystate" If Not __IEIsObjType($o_object, "browser") Then __IEErrorNotify("Error", "_IEPropertyGet", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf Return SetError($_IEStatus_Success, 0, $o_object.ReadyState()) Case $s_property = "resizable" If Not __IEIsObjType($o_object, "browser") Then __IEErrorNotify("Error", "_IEPropertyGet", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf Return SetError($_IEStatus_Success, 0, $o_object.Resizable()) Case $s_property = "silent" If Not __IEIsObjType($o_object, "browser") Then __IEErrorNotify("Error", "_IEPropertyGet", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf Return SetError($_IEStatus_Success, 0, $o_object.Silent()) Case $s_property = "statusbar" If Not __IEIsObjType($o_object, "browser") Then __IEErrorNotify("Error", "_IEPropertyGet", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf Return SetError($_IEStatus_Success, 0, $o_object.StatusBar()) Case $s_property = "statustext" If Not __IEIsObjType($o_object, "browser") Then __IEErrorNotify("Error", "_IEPropertyGet", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf Return SetError($_IEStatus_Success, 0, $o_object.StatusText()) Case $s_property = "top" If Not __IEIsObjType($o_object, "browser") Then __IEErrorNotify("Error", "_IEPropertyGet", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf Return SetError($_IEStatus_Success, 0, $o_object.Top()) Case $s_property = "visible" If Not __IEIsObjType($o_object, "browser") Then __IEErrorNotify("Error", "_IEPropertyGet", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf Return SetError($_IEStatus_Success, 0, $o_object.Visible()) Case $s_property = "appcodename" Return SetError($_IEStatus_Success, 0, $o_object.document.parentWindow.top.navigator.appCodeName()) Case $s_property = "appminorversion" Return SetError($_IEStatus_Success, 0, $o_object.document.parentWindow.top.navigator.appMinorVersion()) Case $s_property = "appname" Return SetError($_IEStatus_Success, 0, $o_object.document.parentWindow.top.navigator.appName()) Case $s_property = "appversion" Return SetError($_IEStatus_Success, 0, $o_object.document.parentWindow.top.navigator.appVersion()) Case $s_property = "browserlanguage" Return SetError($_IEStatus_Success, 0, $o_object.document.parentWindow.top.navigator.browserLanguage()) Case $s_property = "cookieenabled" Return SetError($_IEStatus_Success, 0, $o_object.document.parentWindow.top.navigator.cookieEnabled()) Case $s_property = "cpuclass" Return SetError($_IEStatus_Success, 0, $o_object.document.parentWindow.top.navigator.cpuClass()) Case $s_property = "javaenabled" Return SetError($_IEStatus_Success, 0, $o_object.document.parentWindow.top.navigator.javaEnabled()) Case $s_property = "online" Return SetError($_IEStatus_Success, 0, $o_object.document.parentWindow.top.navigator.onLine()) Case $s_property = "platform" Return SetError($_IEStatus_Success, 0, $o_object.document.parentWindow.top.navigator.platform()) Case $s_property = "systemlanguage" Return SetError($_IEStatus_Success, 0, $o_object.document.parentWindow.top.navigator.systemLanguage()) Case $s_property = "useragent" Return SetError($_IEStatus_Success, 0, $o_object.document.parentWindow.top.navigator.userAgent()) Case $s_property = "userlanguage" Return SetError($_IEStatus_Success, 0, $o_object.document.parentWindow.top.navigator.userLanguage()) Case $s_property = "referrer" Return SetError($_IEStatus_Success, 0, $o_object.document.referrer) Case $s_property = "theatermode" If Not __IEIsObjType($o_object, "browser") Then __IEErrorNotify("Error", "_IEPropertyGet", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf Return SetError($_IEStatus_Success, 0, $o_object.TheaterMode) Case $s_property = "toolbar" If Not __IEIsObjType($o_object, "browser") Then __IEErrorNotify("Error", "_IEPropertyGet", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf Return SetError($_IEStatus_Success, 0, $o_object.ToolBar) Case $s_property = "contenteditable" If __IEIsObjType($o_object, "browser") Or __IEIsObjType($o_object, "document") Then $oTemp = $o_object.document.body Else $oTemp = $o_object EndIf Return SetError($_IEStatus_Success, 0, $oTemp.isContentEditable) Case $s_property = "innertext" If __IEIsObjType($o_object, "documentcontainer") Or __IEIsObjType($o_object, "document") Then $oTemp = $o_object.document.body Else $oTemp = $o_object EndIf Return SetError($_IEStatus_Success, 0, $oTemp.innerText) Case $s_property = "outertext" If __IEIsObjType($o_object, "documentcontainer") Or __IEIsObjType($o_object, "document") Then $oTemp = $o_object.document.body Else $oTemp = $o_object EndIf Return SetError($_IEStatus_Success, 0, $oTemp.outerText) Case $s_property = "innerhtml" If __IEIsObjType($o_object, "documentcontainer") Or __IEIsObjType($o_object, "document") Then $oTemp = $o_object.document.body Else $oTemp = $o_object EndIf Return SetError($_IEStatus_Success, 0, $oTemp.innerHTML) Case $s_property = "outerhtml" If __IEIsObjType($o_object, "documentcontainer") Or __IEIsObjType($o_object, "document") Then $oTemp = $o_object.document.body Else $oTemp = $o_object EndIf Return SetError($_IEStatus_Success, 0, $oTemp.outerHTML) Case $s_property = "title" Return SetError($_IEStatus_Success, 0, $o_object.document.title) Case $s_property = "uniqueid" If __IEIsObjType($o_object, "window") Then __IEErrorNotify("Error", "_IEPropertyGet", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) Else Return SetError($_IEStatus_Success, 0, $o_object.uniqueID) EndIf Case Else ; Unsupported Property __IEErrorNotify("Error", "_IEPropertyGet", "$_IEStatus_InvalidValue", "Invalid Property") Return SetError($_IEStatus_InvalidValue, 2, 0) EndSelect EndFunc ;==>_IEPropertyGet ; #FUNCTION# ==================================================================================================================== ; Name...........: _IEPropertySet ; Description ...: Set a select property of the Browser ; Parameters ....: $o_object - Object variable of an InternetExplorer.Application ; $s_property - Property selection ; $newvalue - The new value to be set into the Browser Property ; Return values .: On Success - Returns 1 ; On Failure - Returns 0 and sets @error ; @error - 0 ($_IEStatus_Success) = No Error ; - 3 ($_IEStatus_InvalidDataType) = Invalid Data Type ; - 4 ($_IEStatus_InvalidObjectType) = Invalid Object Type ; - 5 ($_IEStatus_InvalidValue) = Invalid Value ; @extended - Contains invalid parameter number ; Author ........: Dale Hohm ; =============================================================================================================================== Func _IEPropertySet(ByRef $o_object, $s_property, $newvalue) If Not IsObj($o_object) Then __IEErrorNotify("Error", "_IEPropertySet", "$_IEStatus_InvalidDataType") Return SetError($_IEStatus_InvalidDataType, 1, 0) EndIf ; Local $oTemp #forceref $oTemp $s_property = StringLower($s_property) Select Case $s_property = "addressbar" If Not __IEIsObjType($o_object, "browser") Then __IEErrorNotify("Error", "_IEPropertySet", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf $o_object.AddressBar = $newvalue Case $s_property = "height" If Not __IEIsObjType($o_object, "browser") Then __IEErrorNotify("Error", "_IEPropertySet", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf $o_object.Height = $newvalue Case $s_property = "left" If Not __IEIsObjType($o_object, "browser") Then __IEErrorNotify("Error", "_IEPropertySet", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf $o_object.Left = $newvalue Case $s_property = "menubar" If Not __IEIsObjType($o_object, "browser") Then __IEErrorNotify("Error", "_IEPropertySet", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf $o_object.MenuBar = $newvalue Case $s_property = "offline" If Not __IEIsObjType($o_object, "browser") Then __IEErrorNotify("Error", "_IEPropertySet", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf $o_object.OffLine = $newvalue Case $s_property = "resizable" If Not __IEIsObjType($o_object, "browser") Then __IEErrorNotify("Error", "_IEPropertySet", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf $o_object.Resizable = $newvalue Case $s_property = "statusbar" If Not __IEIsObjType($o_object, "browser") Then __IEErrorNotify("Error", "_IEPropertySet", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf $o_object.StatusBar = $newvalue Case $s_property = "statustext" If Not __IEIsObjType($o_object, "browser") Then __IEErrorNotify("Error", "_IEPropertySet", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf $o_object.StatusText = $newvalue Case $s_property = "top" If Not __IEIsObjType($o_object, "browser") Then __IEErrorNotify("Error", "_IEPropertySet", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf $o_object.Top = $newvalue Case $s_property = "width" If Not __IEIsObjType($o_object, "browser") Then __IEErrorNotify("Error", "_IEPropertySet", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf $o_object.Width = $newvalue Case $s_property = "theatermode" If Not __IEIsObjType($o_object, "browser") Then __IEErrorNotify("Error", "_IEPropertySet", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf If $newvalue Then $o_object.TheaterMode = True Else $o_object.TheaterMode = False EndIf Case $s_property = "toolbar" If Not __IEIsObjType($o_object, "browser") Then __IEErrorNotify("Error", "_IEPropertySet", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf If $newvalue Then $o_object.ToolBar = True Else $o_object.ToolBar = False EndIf Case $s_property = "contenteditable" If __IEIsObjType($o_object, "browser") Or __IEIsObjType($o_object, "document") Then $oTemp = $o_object.document.body Else $oTemp = $o_object EndIf If $newvalue Then $oTemp.contentEditable = "true" Else $oTemp.contentEditable = "false" EndIf Case $s_property = "innertext" If __IEIsObjType($o_object, "documentcontainer") Or __IEIsObjType($o_object, "document") Then $oTemp = $o_object.document.body Else $oTemp = $o_object EndIf $oTemp.innerText = $newvalue Case $s_property = "outertext" If __IEIsObjType($o_object, "documentcontainer") Or __IEIsObjType($o_object, "document") Then $oTemp = $o_object.document.body Else $oTemp = $o_object EndIf $oTemp.outerText = $newvalue Case $s_property = "innerhtml" If __IEIsObjType($o_object, "documentcontainer") Or __IEIsObjType($o_object, "document") Then $oTemp = $o_object.document.body Else $oTemp = $o_object EndIf $oTemp.innerHTML = $newvalue Case $s_property = "outerhtml" If __IEIsObjType($o_object, "documentcontainer") Or __IEIsObjType($o_object, "document") Then $oTemp = $o_object.document.body Else $oTemp = $o_object EndIf $oTemp.outerHTML = $newvalue Case $s_property = "title" $o_object.document.title = $newvalue Case $s_property = "silent" If Not __IEIsObjType($o_object, "browser") Then __IEErrorNotify("Error", "_IEPropertySet", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf If $newvalue Then $o_object.silent = True Else $o_object.silent = False EndIf Case Else ; Unsupported Property __IEErrorNotify("Error", "_IEPropertySet", "$_IEStatus_InvalidValue", "Invalid Property") Return SetError($_IEStatus_InvalidValue, 2, 0) EndSelect If @error Then ; Trap COM error, report and return Local $s_error = @error, $s_function_name = "_IEPropertySet" __IEErrorNotify("Error", $s_function_name, "$_IEStatus_COMError", $s_error) Return SetError($_IEStatus_ComError, $s_error, 0) EndIf Return SetError($_IEStatus_Success, 0, 0) EndFunc ;==>_IEPropertySet ; #FUNCTION# ==================================================================================================================== ; Name...........: _IEErrorNotify ; Description ...: Specifies whether IE.au3 automatically notifies of Warnings and Errors (to the console) ; Parameters ....: $f_notify - Optional: specifies whether notification should be on or off ; - -1 = (Default) return current setting ; - True = Turn On ; - False = Turn Off ; Return values .: On Success - If $f_notify = -1, returns the current notification setting, else returns 1 ; On Failure - Returns 0 ; Author ........: Dale Hohm ; =============================================================================================================================== Func _IEErrorNotify($f_notify = -1) Switch Number($f_notify) Case -1 Return $_IEErrorNotify Case 0 $_IEErrorNotify = False Return 1 Case 1 $_IEErrorNotify = True Return 1 Case Else __IEErrorNotify("Error", "_IEErrorNotify", "$_IEStatus_InvalidValue") Return 0 EndSwitch EndFunc ;==>_IEErrorNotify ; #FUNCTION# ==================================================================================================================== ; Name...........: _IEQuit ; Description ...: Close the browser and remove the object reference to it ; Parameters ....: $o_object - Object variable of an InternetExplorer.Application ; Return values .: On Success - Returns 1 ; On Failure - Returns 0 and sets @error ; @error - 0 ($_IEStatus_Success) = No Error ; - 3 ($_IEStatus_InvalidDataType) = Invalid Data Type ; - 4 ($_IEStatus_InvalidObjectType) = Invalid Object Type ; @extended - Contains invalid parameter number ; Author ........: Dale Hohm ; =============================================================================================================================== Func _IEQuit(ByRef $o_object) If Not IsObj($o_object) Then __IEErrorNotify("Error", "_IEQuit", "$_IEStatus_InvalidDataType") Return SetError($_IEStatus_InvalidDataType, 1, 0) EndIf ; If Not __IEIsObjType($o_object, "browser") Then __IEErrorNotify("Error", "_IEAction", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf ; $o_object.quit() If @error Then ; Trap COM error, report and return Local $s_error = @error, $s_function_name = "_IEQuit" __IEErrorNotify("Error", $s_function_name, "$_IEStatus_COMError", $s_error) Return SetError($_IEStatus_ComError, $s_error, 0) EndIf $o_object = 0 Return SetError($_IEStatus_Success, 0, 1) EndFunc ;==>_IEQuit #endregion Utility functions #region General ; #FUNCTION# ==================================================================================================================== ; Name...........: _IE_Introduction ; Description ...: Display introductory information about IE.au3 in a new browser window ; Parameters ....: $s_module - Optional: specifies which module to run ; - basic = (Default) basic introduction ; Return values .: On Success - Returns an object variable pointing to an InternetExplorer.Application object ; On Failure - Returns 0 and sets @error ; @error - 0 ($_IEStatus_Success) = No Error ; - 5 ($_IEStatus_InvalidValue) = Invalid Value ; @extended - Contains invalid parameter number ; Author ........: Dale Hohm ; =============================================================================================================================== Func _IE_Introduction($s_module = "basic") Local $s_html = "" Switch $s_module Case "basic" $s_html &= "" & @CR $s_html &= "" & @CR $s_html &= "" & @CR
$s_html &= "Welcome to IE.au3" & @CR $s_html &= "IE.au3 is a UDF (User Defined Function) library for the " & @CR $s_html &= "AutoIt scripting language." & @CR $s_html &= "" & @CR $s_html &= "IE.au3 allows you to either create or attach to an Internet Explorer browser and do " & @CR $s_html &= "just about anything you could do with it interactively with the mouse and " & @CR $s_html &= "keyboard, but do it through script." & @CR $s_html &= " " & @CR $s_html &= "You can navigate to pages, click links, fill and submit forms etc. You can " & @CR $s_html &= "also do things you cannot do interactively like change or rewrite page " & @CR $s_html &= "content and JavaScripts, read, parse and save page content and monitor and act " & @CR $s_html &= "upon browser 'events'. " & @CR $s_html &= "IE.au3 uses the COM interface in AutoIt to interact with the Internet Explorer " & @CR $s_html &= "object model and the DOM (Document Object Model) supported by the browser." & @CR $s_html &= " " & @CR $s_html &= "Here are some links for more information and helpful tools: " & @CR $s_html &= "Reference Material: " & @CR $s_html &= "
" & @CR $s_html &= "Helpful Tools: " & @CR $s_html &= "
| " & @CR
$s_html &= "
" & @CR $s_html &= "
" & @CR $s_html &= "
" & @CR $s_html &= "
" & @CR $s_html &= "
" & @CR $s_html &= "" & @CR $s_html &= "" $o_object = _IECreate() _IEDocWriteHTML($o_object, $s_html) Case "table" $s_html &= "" & @CR $s_html &= "" & @CR $s_html &= "" & @CR $s_html &= "
AutoIt | " & @CR $s_html &= "is | " & @CR $s_html &= "really | " & @CR $s_html &= "great | " & @CR $s_html &= "with | " & @CR $s_html &= "IE.au3 | " & @CR $s_html &= "
1 | " & @CR $s_html &= "2 | " & @CR $s_html &= "3 | " & @CR $s_html &= "4 | " & @CR $s_html &= "5 | " & @CR $s_html &= "6 | " & @CR $s_html &= "
the | " & @CR $s_html &= "quick | " & @CR $s_html &= "red | " & @CR $s_html &= "fox | " & @CR $s_html &= "jumped | " & @CR $s_html &= "over | " & @CR $s_html &= "
the | " & @CR $s_html &= "lazy | " & @CR $s_html &= "brown | " & @CR $s_html &= "dog | " & @CR $s_html &= "the | " & @CR $s_html &= "time | " & @CR $s_html &= "
has | " & @CR $s_html &= "come | " & @CR $s_html &= "for | " & @CR $s_html &= "all | " & @CR $s_html &= "good | " & @CR $s_html &= "men | " & @CR $s_html &= "
to | " & @CR $s_html &= "come | " & @CR $s_html &= "to | " & @CR $s_html &= "the | " & @CR $s_html &= "aid | " & @CR $s_html &= "of | " & @CR $s_html &= "
" & @CR
$s_html &= "$oTableTwo = _IETableGetObjByName($oIE, "tableTwo")
" & @CR
$s_html &= "<table border="1" id='tableTwo'>
" & @CR $s_html &= "
Table Top | " & @CR $s_html &= "|||
One | " & @CR $s_html &= "Two | " & @CR $s_html &= "||
Three | " & @CR $s_html &= "Four | " & @CR $s_html &= "Five | " & @CR $s_html &= "|
Six | " & @CR $s_html &= "Seven | " & @CR $s_html &= "||
Eight | " & @CR $s_html &= "Nine | " & @CR $s_html &= "Ten | " & @CR $s_html &= "Eleven | " & @CR $s_html &= "
" & @CR $s_html &= " | <iframe name="iFrameOne" src="about:blank" title="iFrameOne"> | " & @CR $s_html &= "
" & @CR $s_html &= " | <iframe name="iFrameTwo" src="about:blank" title="iFrameTwo"> | " & @CR $s_html &= "