sproxy
Full Member | Редактировать | Профиль | Сообщение | ICQ | Цитировать | Сообщить модератору Код: ;~ #include <IE.au3> $IE = _IECreate() $rezultat = Call("_IEAction", $IE, "saveas") MsgBox(0, $rezultat, @error) #include-once #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: V2.4-1 Last Update: 4/26/08 Requirements: AutoIt3 3.2 or higher, Developed/Tested on WindowsXP Pro with Internet Explorer6 and Internet Explorer7 Note: Special thanks to big_daddy for working on documentation and creating helpfile for T2.0! Update History: =================================================== V2.4-1 4/26/08 Fixes _IEAttach, windowtitle, fixed bug matching window title when IE windowtitle registry key is not set _IEPropertyGet, toolbars, broken, now works New Features Enhancements _IEGetObjById added requested Id to console output on NoMatch _IEGetObjByName added requested Id and index to console output on NoMatch --------------------------------------------------- V2.4-0 12/31/07 Fixes _IELoadWait looping logic corrected to prevent nuisance console COM messages with small loadwait timeouts _IEAttach embedded and dialogbox modes update DllCall syntax (hopefully works with bugfix to DllCall post 3.2.10.0 that caused embedded to fail) _IEAttach moved Shell.Window object creation after embedded/dialogbox logic so that they can run without explorer.exe running _IECreate and _IENavigate documentation, added Windows Vista UAC information _IEFormElementGetValue returns NULL string if value is NULL instead of integer 0 New Features Added uniqueID to _IEPropertyGet Added "instance" mode to _IEAttach Added "$i_instance" parameter to _IEAttach - thanks to my 13-year-old daughter for helping me think through the logic of the _IEAttach additions --------------------------------------------------- V2.3-1 8/13/07 Fixes _IELoadWait to handle "Access is denied" errors in foreign language variants _IEFormElementCheckBoxSelect and _IEFormElementRadioSelect errors with singletons Enhancements Enhanced _IEPropertyGet() width and height to work for document elements in addition to the browser window New Features Added browserX, browserY, screenX and screenY to _IEPropertyGet() Added Transpose option to _IETableWriteToArray --------------------------------------------------- V2.3-0 8/11/07 This version was not released due to regression corrected in V2.3-1 --------------------------------------------------- V2.2-1 5/9/07 Fixes Trap and report Client Disconnected errors in _IELoadWait when Browser is deleted prior to operation --------------------------------------------------- V2.2-0 5/8/07 Fixes Fixed typos in _IEPropertyGet() directives appversion and appminorversion Updated links in _IE_Introduction('basic') Enhancements Several documentation New Features _IEGetObjById() added --------------------------------------------------- V2.1-0 12/16/06 Fixes _IEFormElementOptionSelect() - fixed problem with using "byText" mode that resulted in always selecting a blank text choice if it existed _IEAttach() - fixed error generated if certain IE emulators were running (e.g. Firefox IETab extension, Maxathon etc.) Forced datatype to String for many internal variables where unexpected numerics could have caused erroneous condition matches Modified _IELoadWait() to trap and report more cases of "Access is Denied" cross-domain security errors Modified _IEFormElementCheckboxSelect() and _IEFormElementRadioSelect() so that element name resolution is scoped to the form (Thanks martijn) Enhancements Modified _IEFormElementSetValue() and _IEFormElement*Select() functions to fire onClick event in addition to onChange event Generate error if _IEFormElementSetValue() attempted on IMPUT TYPE=FILE element New Features _IEPropertyGet() - added referrer, theatermode, toolbar, contenteditable, innertext, outertext, innerhtml, outerhtml, title _IEPropertySet() - added theatermode, toolbar, contenteditable, innertext, outertext, innerhtml, outerhtml, title, silent _IEAttach() - added "windowtitle" mode that will attempt to match a substring in the full window title instead of document title _IEDocInsertText() function added _IEDocInsertHTML() function added Changes _IETableWriteToArray now reads TH (table header) cells into the output array instead of ignoring them _IEPropertySet removed LocationName and LocationURL that were read-only - please use _IENavigate instead Developer Notes added __IENavigate to Internal Functions to test 4 new parameters to the browser Navigate method - see header notes Previous version, T2.0-5, was released with AutoIt V3.2 --------------------------------------------------- =================================================== #ce #EndRegion Header #Region Global Variables and Constants Global Const $IEAU3VersionInfo[6] = ["V", 2, 4, 0, "20071231", "V2.4-0"] Global Const $LSFW_LOCK = 1, $LSFW_UNLOCK = 2 Global $__IELoadWaitTimeout = 300000 ; 5 Minutes Global $__IEAU3Debug = False Global $__IEAU3V1Compatibility Global $__IEAU3Debug_UseOldDLLCall = False Global $_IEErrorNotify = True Global $oIEErrorHandler, $sIEUserErrorHandler Global _; Com Error Handler Status Strings $IEComErrorNumber, _ $IEComErrorNumberHex, _ $IEComErrorDescription, _ $IEComErrorScriptline, _ $IEComErrorWinDescription, _ $IEComErrorSource, _ $IEComErrorHelpFile, _ $IEComErrorHelpContext, _ $IEComErrorLastDllError, _ $IEComErrorComObj, _ $IEComErrorOutput ; ; 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 Variables and Constants #Region Core functions ;=============================================================================== ; ; Function Name: _IECreate() ; Description: Create an Internet Explorer Browser Window ; Parameter(s): $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 ; Requirement(s): AutoIt3 V3.2 or higher ; Return Value(s): 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(s): Dale Hohm ; ;=============================================================================== ; Func _IECreate($s_Url = "about:blank", $f_tryAttach = 0, $f_visible = 1, $f_wait = 1, $f_takeFocus = 1) Local $result, $f_mustUnlock = 0 ; Temporary campatability mode for pre V2.0 code If $__IEAU3V1Compatibility Then Switch String($s_Url) Case "0" $s_Url = "about:blank" $f_visible = 0 __IEErrorNotify("Warning", "_IECreate", "", _ "Using deprecated behavior - $f_visible is now parameter 3 instead of parameter 1") Case "1" $s_Url = "about:blank" $f_visible = 1 __IEErrorNotify("Warning", "_IECreate", "", _ "Using deprecated behavior - $f_visible is now parameter 3 instead of parameter 1") EndSwitch EndIf 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)) SetError($_IEStatus_Success) SetExtended(1) Return $oResult EndIf EndIf If Not $f_visible Then $result = __IELockSetForegroundWindow($LSFW_LOCK) If $result Then $f_mustUnlock = 1 EndIf Local $o_object = ObjCreate("InternetExplorer.Application") If Not IsObj($o_object) Then __IEErrorNotify("Error", "_IECreate", "", "Browser Object Creation Failed") SetError($_IEStatus_GeneralError) Return 0 EndIf $o_object.visible = $f_visible If $f_mustUnlock Then $result = __IELockSetForegroundWindow($LSFW_UNLOCK) If Not $result Then __IEErrorNotify("Warning", "_IECreate", "", "Foreground Window Unlock Failed!") ; If the unlock doesn't work we may have created an unwanted modal window EndIf _IENavigate($o_object, $s_Url, $f_wait) SetError(@error) Return $o_object EndFunc ;==>_IECreate ;=============================================================================== ; ; Function Name: _IECreateEmbedded() ; Description: Create a Webbrowser object suitable for embedding in an AutoIt GUI ; with GuiCtrlCreateObj(). ; Parameter(s): None ; Requirement(s): AutoIt3 V3.2 or higher ; Return Value(s): 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(s): Dale Hohm ; ;=============================================================================== ; Func _IECreateEmbedded() Local $o_object = ObjCreate("Shell.Explorer.2") If Not IsObj($o_object) Then __IEErrorNotify("Error", "_IECreateEmbedded", "", "WebBrowser Object Creation Failed") SetError($_IEStatus_GeneralError) Return 0 EndIf ; SetError($_IEStatus_Success) Return $o_object EndFunc ;==>_IECreateEmbedded ;=============================================================================== ; ; Function Name: _IENavigate() ; Description: Directs an existing browser window to navigate to the specified URL ; Parameter(s): $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 ; Requirement(s): AutoIt3 V3.2 or higher ; Return Value(s): 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(s): Dale Hohm ; ;=============================================================================== ; Func _IENavigate(ByRef $o_object, $s_Url, $f_wait = 1) If Not IsObj($o_object) Then __IEErrorNotify("Error", "_IENavigate", "$_IEStatus_InvalidDataType") SetError($_IEStatus_InvalidDataType, 1) Return 0 EndIf ; If Not __IEIsObjType($o_object, "documentContainer") Then __IEErrorNotify("Error", "_IENavigate", "$_IEStatus_InvalidObjectType") SetError($_IEStatus_InvalidObjectType, 1) Return 0 EndIf ; $o_object.navigate($s_Url) If $f_wait Then _IELoadWait($o_object) SetError(@error) Return -1 EndIf SetError($_IEStatus_Success) Return -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. ; Parameter(s): $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 ; Requirement(s): AutoIt3 V3.2 or higher ; 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(s): Dale Hohm ; ;=============================================================================== ; Func _IEAttach($s_string, $s_mode = "Title", $i_instance = 1) $s_mode = StringLower($s_mode) Local $h_control, $oResult, $f_isBrowser, $s_tmp, $i_tmp $i_instance = Int($i_instance) If $i_instance < 1 Then __IEErrorNotify("Error", "_IEAttach", "$_IEStatus_InvalidValue", "$i_instance < 1") SetError($_IEStatus_InvalidValue, 3) Return 0 EndIf If $s_mode = "embedded" Or $s_mode = "dialogbox" Then Local $iWinTitleMatchMode = Opt("WinTitleMatchMode") 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") SetError($_IEStatus_NoMatch, 1) Return 0 EndIf EndIf EndIf $h_control = ControlGetHandle($s_string, "", "[CLASS:Internet Explorer_Server; INSTANCE:" & $i_instance & "]") $oResult = __IEControlGetObjFromHWND($h_control) Opt("WinTitleMatchMode", $iWinTitleMatchMode) If IsObj($oResult) Then SetError($_IEStatus_Success) Return $oResult Else __IEErrorNotify("Warning", "_IEAttach", "$_IEStatus_NoMatch") SetError($_IEStatus_NoMatch, 1) Return 0 EndIf EndIf Local $o_Shell = ObjCreate("Shell.Application") Local $o_ShellWindows = $o_Shell.Windows(); collection of all ShellWindows (IE and File Explorer) $i_tmp = 1 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 ; Trap COM errors and turn off error notification Local $status = __IEInternalErrorHandlerRegister() If Not $status Then __IEErrorNotify("Warning", "_IEAttach", _ "Cannot register internal error handler, cannot trap COM errors", _ "Use _IEErrorHandlerRegister() to register a user error handler") Local $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 and error handler status _IEErrorNotify($f_NotifyStatus) ; restore notification status __IEInternalErrorHandlerDeRegister() ;------------------------------------------------------------------------------------------ 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 SetError($_IEStatus_Success) Return $o_window Else $i_tmp += 1 EndIf EndIf Case "instance" If $i_instance = $i_tmp Then SetError($_IEStatus_Success) Return $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 SetError($_IEStatus_Success) Return $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 SetError($_IEStatus_Success) Return $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 SetError($_IEStatus_Success) Return $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 SetError($_IEStatus_Success) Return $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 SetError($_IEStatus_Success) Return $o_window EndIf Case Else ; Invalid Mode __IEErrorNotify("Error", "_IEAttach", "$_IEStatus_InvalidValue", "Invalid Mode Specified") SetError($_IEStatus_InvalidValue, 2) Return 0 EndSwitch EndIf Next __IEErrorNotify("Warning", "_IEAttach", "$_IEStatus_NoMatch") SetError($_IEStatus_NoMatch, 1) Return 0 EndFunc ;==>_IEAttach ;=============================================================================== ; ; Function Name: _IELoadWait() ; Description: Wait for a browser page load to complete before returning ; Parameter(s): $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) ; Requirement(s): AutoIt3 V3.2 or higher ; Return Value(s): 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(s): Dale Hohm ; ; Developer notes: 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") SetError($_IEStatus_InvalidDataType, 1) Return 0 EndIf If Not __IEIsObjType($o_object, "browserdom") Then __IEErrorNotify("Error", "_IELoadWait", "$_IEStatus_InvalidObjectType", ObjName($o_object)) SetError($_IEStatus_InvalidObjectType, 1) Return 0 EndIf Local $oTemp, $f_Abort = False, $i_ErrorStatusCode = $_IEStatus_Success ; Setup internal error handler to Trap COM errors, turn off error notification Local $status = __IEInternalErrorHandlerRegister() If Not $status Then __IEErrorNotify("Warning", "_IELoadWait", _ "Cannot register internal error handler, cannot trap COM errors", _ "Use _IEErrorHandlerRegister() to register a user error handler") Local $f_NotifyStatus = _IEErrorNotify() ; save current error notify status _IEErrorNotify(False) Sleep($i_delay) ; Local $IELoadWaitTimer = TimerInit() If $i_timeout = -1 Then $i_timeout = $__IELoadWaitTimeout Switch ObjName($o_object) Case "IWebBrowser2"; InternetExplorer While Not (String($o_object.readyState) = "complete" Or $o_object.readyState = 4 Or $f_Abort) ; Trap unrecoverable COM errors If (TimerDiff($IELoadWaitTimer) > $i_timeout) Then $i_ErrorStatusCode = $_IEStatus_LoadWaitTimeout $f_Abort = True EndIf If @error = $_IEStatus_ComError And __IEComErrorUnrecoverable() Then $i_ErrorStatusCode = __IEComErrorUnrecoverable() $f_Abort = True EndIf Sleep(100) WEnd While Not (String($o_object.document.readyState) = "complete" Or $o_object.document.readyState = 4 Or $f_Abort) If (TimerDiff($IELoadWaitTimer) > $i_timeout) Then $i_ErrorStatusCode = $_IEStatus_LoadWaitTimeout $f_Abort = True EndIf ; Trap unrecoverable COM errors If @error = $_IEStatus_ComError And __IEComErrorUnrecoverable() Then $i_ErrorStatusCode = __IEComErrorUnrecoverable() $f_Abort = True EndIf Sleep(100) WEnd Case "DispHTMLWindow2" ; Window, Frame, iFrame While Not (String($o_object.document.readyState) = "complete" Or $o_object.document.readyState = 4 Or $f_Abort) If (TimerDiff($IELoadWaitTimer) > $i_timeout) Then $i_ErrorStatusCode = $_IEStatus_LoadWaitTimeout $f_Abort = True EndIf ; Trap unrecoverable COM errors If @error = $_IEStatus_ComError And __IEComErrorUnrecoverable() Then $i_ErrorStatusCode = __IEComErrorUnrecoverable() $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) If (TimerDiff($IELoadWaitTimer) > $i_timeout) Then $i_ErrorStatusCode = $_IEStatus_LoadWaitTimeout $f_Abort = True EndIf ; Trap unrecoverable COM errors If @error = $_IEStatus_ComError And __IEComErrorUnrecoverable() Then $i_ErrorStatusCode = __IEComErrorUnrecoverable() $f_Abort = True EndIf Sleep(100) WEnd Case "DispHTMLDocument" ; Document $oTemp = $o_object.parentWindow While Not (String($oTemp.document.readyState) = "complete" Or $oTemp.document.readyState = 4 Or $f_Abort) If (TimerDiff($IELoadWaitTimer) > $i_timeout) Then $i_ErrorStatusCode = $_IEStatus_LoadWaitTimeout $f_Abort = True EndIf ; Trap unrecoverable COM errors If @error = $_IEStatus_ComError And __IEComErrorUnrecoverable() Then $i_ErrorStatusCode = __IEComErrorUnrecoverable() $f_Abort = True EndIf Sleep(100) WEnd While Not (String($oTemp.top.document.readyState) = "complete" Or $oTemp.top.document.readyState = 4 Or $f_Abort) If (TimerDiff($IELoadWaitTimer) > $i_timeout) Then $i_ErrorStatusCode = $_IEStatus_LoadWaitTimeout $f_Abort = True EndIf ; Trap unrecoverable COM errors If @error = $_IEStatus_ComError And __IEComErrorUnrecoverable() Then $i_ErrorStatusCode = __IEComErrorUnrecoverable() $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) If (TimerDiff($IELoadWaitTimer) > $i_timeout) Then $i_ErrorStatusCode = $_IEStatus_LoadWaitTimeout $f_Abort = True EndIf ; Trap unrecoverable COM errors If @error = $_IEStatus_ComError And __IEComErrorUnrecoverable() Then $i_ErrorStatusCode = __IEComErrorUnrecoverable() $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) If (TimerDiff($IELoadWaitTimer) > $i_timeout) Then $i_ErrorStatusCode = $_IEStatus_LoadWaitTimeout $f_Abort = True EndIf ; Trap unrecoverable COM errors If @error = $_IEStatus_ComError And __IEComErrorUnrecoverable() Then $i_ErrorStatusCode = __IEComErrorUnrecoverable() $f_Abort = True EndIf Sleep(100) WEnd EndSwitch ; restore error notify and error handler status _IEErrorNotify($f_NotifyStatus) ; restore notification status __IEInternalErrorHandlerDeRegister() Switch $i_ErrorStatusCode Case $_IEStatus_Success SetError($_IEStatus_Success) Return 1 Case $_IEStatus_LoadWaitTimeout __IEErrorNotify("Warning", "_IELoadWait", "$_IEStatus_LoadWaitTimeout") SetError($_IEStatus_LoadWaitTimeout, 3) Return 0 Case $_IEStatus_AccessIsDenied __IEErrorNotify("Warning", "_IELoadWait", "$_IEStatus_AccessIsDenied", _ "Cannot verify readyState. Likely casue: cross-site scripting security restriction.") SetError($_IEStatus_AccessIsDenied) Return 0 Case $_IEStatus_ClientDisconnected __IEErrorNotify("Error", "_IELoadWait", "$_IEStatus_ClientDisconnected", _ "Browser has been deleted prior to operation.") SetError($_IEStatus_ClientDisconnected) Return 0 Case Else __IEErrorNotify("Error", "_IELoadWait", "$_IEStatus_GeneralError", "Invalid Error Status - Notify IE.au3 developer") SetError($_IEStatus_GeneralError) Return 0 EndSwitch EndFunc ;==>_IELoadWait ;=============================================================================== ; ; Function Name: _IELoadWaitTimeout() ; Description: Retrieve or set the current value in milliseconds _IELoadWait will try before timing out ; Parameter(s): $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) ; Requirement(s): AutoIt3 V3.2 or higher ; Return Value(s): On Success - If $i_timeout = -1, returns the current timeout value, else returns 1 ; On Failure - None ; Author(s): Dale Hohm ; ;=============================================================================== ; Func _IELoadWaitTimeout($i_timeout = -1) If $i_timeout = -1 Then SetError($_IEStatus_Success) Return $__IELoadWaitTimeout Else $__IELoadWaitTimeout = $i_timeout SetError($_IEStatus_Success) Return 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 | | Всего записей: 556 | Зарегистр. 21-11-2007 | Отправлено: 16:32 21-02-2009 | Исправлено: sproxy, 16:34 21-02-2009 |
|