Davidowicza Posted July 16, 2019 Share Posted July 16, 2019 (edited) Hey guys, I am getting a COM error that I am struggling to resolve. It happens at random times but in the same area. I am automating a printing job that goes through and prints all of the applications for the day for my agency. Unfortunately I cannot share access to the website since its government related so I will provide as much detail as I possibly can. Here is my script: expandcollapse popup#INCLUDE <IE.au3> Opt("wintitlematchmode",2) _IEErrorHandlerRegister(_User_ErrFunc) $URL = "https://njfc.force.com/admintool/login" $sUser = InputBox("Enter Username", "Username:","","",30,130) $sPass = InputBox("Enter Password", "Password:","","",30,130) ;Open IE ;Created a loop since after roughly 18 apps the _IE functions would start failing. for $x = 1 to 25 ;Will print up to 125 apps. $o_IE = _IECreate($URL) ;Set window to Maximum $hwnd = _IEPropertyGet($o_IE, "hwnd") WinSetState($hwnd,"",@SW_MAXIMIZE) ;Search through the website and insert the information $oInputs = _IETagNameGetCollection($o_IE, "Input") if @error Then MsgBox($MB_ICONERROR, '_IETAGNAME LOGIN', '@error = ' & @error & @CRLF & '@extended = ' & @extended) EndIf for $oInput In $oInputs If $oInput.name = 'username' Then $oInput.value = $sUser If $oInput.name = 'pw' Then $oInput.value = $sPass Next sleep(500) ;Search for Login button and click it for $oInput In $oInputs If $oInput.name = 'Login' Then _IEAction($oInput, "click") if @error Then MsgBox($MB_ICONERROR, '_IEAction click Login', '@error = ' & @error & @CRLF & '@extended = ' & @extended) EndIf EndIf Next sleep(5000) ;Wait for the Next button to appear then click it $bFound = False $iTimer = TimerInit() While TimerDiff($iTimer) < 5000 AND $bFound = False $oInputs = _IETagNameGetCollection($o_IE, "Input") if @error Then MsgBox($MB_ICONERROR, '_IETagNameGetCollection Next button', '@error = ' & @error & @CRLF & '@extended = ' & @extended) EndIf for $oInput In $oInputs If $oInput.name = 'thePage:j_id2:i:f:pb:pbb:nextAjax' Then Sleep(4000) _IEAction($oInput, "click") if @error Then MsgBox($MB_ICONERROR, '_IEAction Next click', '@error = ' & @error & @CRLF & '@extended = ' & @extended) EndIf $bFound = True EndIf Next sleep(100) WEnd ;Error checking. If $bFound = False Then MsgBox(0,"Error","Could not find NEXT button. Try again. If this is a constant error, please contact IT.") Exit EndIf ;Long wait for the dropdown list to show all the entries to appear. $bFound = False $iTimer2 = TimerInit() While TimerDiff($iTimer2) < 45000 AND $bFound = False $oSelects = _IETagNameGetCollection($o_IE, "Select") if @error Then MsgBox($MB_ICONERROR, '_IETAGNAMECollection droplist', '@error = ' & @error & @CRLF & '@extended = ' & @extended) EndIf for $oSelect In $oSelects If $oSelect.name = 'theTable_length' Then _IEAction($oSelect, "click") if @error Then MsgBox($MB_ICONERROR, '_IEAction click dropdown', '@error = ' & @error & @CRLF & '@extended = ' & @extended) EndIf Send("{DOWN}") Send("{DOWN}") Send("{DOWN}") $bFound = True EndIf Next sleep(100) WEnd If $bFound = False Then MsgBox(0, "Error", "Could not find dropdown. Please try again.") EndIf Sleep(1000) ;This is where we loop through up to 100 entries on the page. If there are more, they just need to rerun the script. $nNum = 0 $oTableCells = _IETagNameGetCollection($o_IE, "TD") if @error Then MsgBox($MB_ICONERROR, '_IETagNameCollection table', '@error = ' & @error & @CRLF & '@extended = ' & @extended) EndIf for $oTableCell In $oTableCells If $nNum > 5 Then ExitLoop ;If we have done 15 apps. restart the program. ;Each app is labeled 'N - New' so we loop through each TD element with that in it. If $oTableCell.innertext = 'N - New' Then _IEAction($oTableCell, "click") If @error Then MsgBox($MB_ICONERROR, '_IEAction table click', '@error = ' & @error & @CRLF & '@extended = ' & @extended) EndIf ;Set timer and wait for the popup for that app to load. $oAs = _IETagNameGetCollection($o_IE, "a") if @error Then MsgBox($MB_ICONERROR, '_IETagNameCollection Status tab', '@error = ' & @error & @CRLF & '@extended = ' & @extended) EndIf For $oA In $oAs ;Click the App Status tab If $oA.id = "ui-id-4" Then Sleep(3000) _IEAction($oA, "click") if @error Then MsgBox($MB_ICONERROR, '_IEAction click status tab', '@error = ' & @error & @CRLF & '@extended = ' & @extended) EndIf EndIf Next Sleep(100) sleep(5000) $oFrame = _IEFrameGetObjByName($o_IE,"j_id53") sleep(500) $oSelects = _IETagNameGetCollection($oFrame, "select") For $oSelect in $oSelects ;Focus on the 'New' and switch it to pending If $oSelect.id = "j_id0:theForm:j_id26:0:APP_status" Then Sleep(2000) _IEFormElementOptionSelect($oSelect, "P - Pending") if @error Then MsgBox($MB_ICONERROR, '_IEFormOptionSelect Pending', '@error = ' & @error & @CRLF & '@extended = ' & @extended) EndIf EndIf Next Sleep(1000) ;Search and find the 'Save' button and click it. $oForm = _IEFormGetObjByName($oFrame,"j_id0:theForm") if @error Then MsgBox($MB_ICONERROR, '_IEGetForm', '@error = ' & @error & @CRLF & '@extended = ' & @extended) EndIf $oInput = _IEGetObjById($oForm, "j_id0:theForm:j_id26:0:cmdSave") if @error Then MsgBox($MB_ICONERROR, '_IEGetObjId Save', '@error = ' & @error & @CRLF & '@extended = ' & @extended) EndIf _IEAction($oInput, "click") if @error Then MsgBox($MB_ICONERROR, '_IEAction click save', '@error = ' & @error & @CRLF & '@extended = ' & @extended) EndIf Sleep(2000) For $oA In $oAs ;Click on the tab that hold the pdf If $oA.id = "ui-id-13" Then _IEAction($oA, "click") if @error Then MsgBox($MB_ICONERROR, '_IEaction click pdf tab', '@error = ' & @error & @CRLF & '@extended = ' & @extended) EndIf EndIf Next Sleep(7000) $oFrame = _IEFrameGetObjByName($o_IE,"j_id71") if @error Then MsgBox($MB_ICONERROR, '_IE iFrame Get PDF', '@error = ' & @error & @CRLF & '@extended = ' & @extended, 3000) EndIf Sleep(500) $oAs = _IETagNameGetCollection($oFrame, "a") For $oA in $oAs ;Click on the link that opens the pdf can be names either review or PEapplicationReview If ($oA.innertext = "Review.pdf") Or ($oA.innertext = "PEapplicationReview.pdf") Then sleep(1000) _IEAction($oA, "click") if @error Then MsgBox($MB_ICONERROR, '_IEaction PDF click', '@error = ' & @error & @CRLF & '@extended = ' & @extended) EndIf EndIf Next Sleep(3000) ;Many issues on this computer interacting with the new tab created. So we are forced to do Send commants to print the app. ;_IELoadWait($o_IE) Cannot do this. Was occasionally getting No Longer Connected to Object error sleep(12000) ;Open printing options Send("^p") WinWait("Print") Sleep(4000) ;Print Send("{ENTER}") ;Wait for upload to printer WinWait("Progress") Sleep(7000) ;Close the app Tab. THIS IS THE ONLY COORDINATE ISSUE WILL SHOULD EVER RUN INTO MouseClick("left",1005, 40,5) ;move the mouse back since it sometimes extended the tabs so they would be off MouseMove(500,500) sleep(5000) ;Close the apps popup $oDivs = _IEGetObjById($o_IE, "escaper") if @error Then MsgBox($MB_ICONERROR, '_IEGetObjID Escaper', '@error = ' & @error & @CRLF & '@extended = ' & @extended,2) EndIf _IEAction($oDivs, "click") if @error Then MsgBox($MB_ICONERROR, '_IEAction Escaper click', '@error = ' & @error & @CRLF & '@extended = ' & @extended,2) EndIf $nNum = $nNum + 1 Sleep(2000) EndIf Next ;Close IE _IEQuit($o_IE) if @error Then MsgBox($MB_ICONERROR, '_IEClose', '@error = ' & @error & @CRLF & '@extended = ' & @extended,2) EndIf Sleep(3000) Next Func _User_ErrFunc($oError) ; Do anything here. ConsoleWrite(@ScriptFullPath & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _ @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _ @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _ @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _ @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _ @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _ @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _ @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _ @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _ @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF) EndFunc ;==>_User_ErrFunc (I stopped using _IELoadWait() since I kept losing connection to the ie object, which could be an issue too) It happens at line 178: $oFrame = _IEFrameGetObjByName($o_IE,"j_id71") This is what the consol returns: expandcollapse popup>"C:\Program Files\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "C:\Bergen\AdminTool.au3" /UserParams +>09:37:36 Starting AutoIt3Wrapper v.19.102.1901.0 SciTE v.4.1.2.0 Keyboard:00000409 OS:WIN_7/Service Pack 1 CPU:X64 OS:X86 Environment(Language:0409) CodePage:0 utf8.auto.check:4 +> SciTEDir => C:\Program Files\AutoIt3\SciTE UserDir => C:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper >Running AU3Check (3.3.14.5) from:C:\Program Files\AutoIt3 input:C:\Bergen\AdminTool.au3 +>09:37:36 AU3Check ended.rc:0 >Running:(3.3.14.5):C:\Program Files\AutoIt3\autoit3.exe "C:\Bergen\AdminTool.au3" +>Setting Hotkeys...--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop C:\Bergen\AdminTool.au3 (1812) : ==> COM Error intercepted ! err.number is: 0x80020008 err.windescription: Bad variable type. err.description is: err.source is: err.helpfile is: err.helpcontext is: err.lastdllerror is: 0 err.scriptline is: 1812 err.retcode is: 0x00000000 C:\Bergen\AdminTool.au3 (1812) : ==> COM Error intercepted ! err.number is: 0x80020008 err.windescription: Bad variable type. err.description is: err.source is: err.helpfile is: err.helpcontext is: err.lastdllerror is: 0 err.scriptline is: 1812 err.retcode is: 0x00000000 C:\Bergen\AdminTool.au3 (713) : ==> COM Error intercepted ! err.number is: 0x000000A9 err.windescription: Variable must be of type 'Object'. err.description is: err.source is: err.helpfile is: err.helpcontext is: err.lastdllerror is: 0 err.scriptline is: 713 err.retcode is: 0x00000000 --> IE.au3 T3.0-2 Warning from function _IEFrameGetObjByName, $_IESTATUS_NoMatch (No Frames found) And the iFrame I am trying to connect to: <iframe name="j_id71" width="100%" height="80%" title="Content" id="j_id71" src="https://njfc.force.com/admintool/apex/FC_Attachment_Tab?confnum=02000846815" frameborder="0" allow="geolocation *; microphone *; camera *"></iframe> The error thrown is @error=7 and @extended=2 which means it could not find the object. The main thing that I do not understand is it works for the first 8-14 applications, then it will randomly throw this error. The element has fully loaded on the page and I am 100% sure that the name of the iFrame did not change. I will provide as much info as possible if you need more. Any help would be appreciated. Thanks. Edited July 17, 2019 by Davidowicza Grammar Link to comment Share on other sites More sharing options...
Nine Posted July 16, 2019 Share Posted July 16, 2019 4 possible solutions (or a mix of them) : 1- Loop doing a refresh until you find the frame by name 2- Use frame collection (in a loop or not, with refresh or not) 3- Get previous object and use nextSibling (element or child) to access the iframe 4- Navigate to the src of the iframe in case of cross-domain Davidowicza 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Davidowicza Posted July 16, 2019 Author Share Posted July 16, 2019 @Nine Thanks, I will try these and let you know! Link to comment Share on other sites More sharing options...
Davidowicza Posted July 17, 2019 Author Share Posted July 17, 2019 I want to thank you @Nine for pointing me in the right direction. Changed when looking for iFrames to this: $bFound = False While $bFound = False $oFrames = _IEFrameGetCollection($o_IE) $iNumFrames = @extended For $i = 0 to ($iNumFrames - 1) $oFrame = _IEFrameGetCollection($o_IE, $i) if $oFrame.name = "j_id53" Then sleep(500) $bFound = True $oSelects = _IETagNameGetCollection($oFrame, "select") ExitLoop EndIf Next sleep(100) WEnd and it works like a charm! (took me so long to respond because after I got this working, other areas were causing me grief so I had to take care of those first) Nine and Earthshine 2 Link to comment Share on other sites More sharing options...
Nine Posted July 17, 2019 Share Posted July 17, 2019 (edited) 3 hours ago, Davidowicza said: I want to thank you @Nine for pointing me in the right direction. But you did the job, glad someone can actually take advise and change it into code ! I am proud of you, really ! You could use leveled Exitloop instead of using boolean, would make your script more readable... Edited July 17, 2019 by Nine Earthshine and Davidowicza 1 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Davidowicza Posted July 18, 2019 Author Share Posted July 18, 2019 (edited) 15 hours ago, Nine said: You could use leveled Exitloop instead of using boolean, would make your script more readable... I actually never knew Exitloop had parameters to work with! It makes life so much easier haha. Thanks for that. Changed to: While 1 $oFrames = _IEFrameGetCollection($o_IE) $iNumFrames = @extended For $i = 0 to ($iNumFrames - 1) $oFrame = _IEFrameGetCollection($o_IE, $i) if $oFrame.name = "j_id53" Then $oSelects = _IETagNameGetCollection($oFrame, "select") ExitLoop(2) EndIf Next sleep(100) WEnd Edited July 18, 2019 by Davidowicza Added code Earthshine 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now