Jump to content
tonycst

IE random crash

Recommended Posts

tonycst
while 1

        If WinActive($AssemblerGUI) > 0 And _IsPressed("0D", $hDLL) = 1 Then ;If GUI is active and ENTER is pressed, execute assemply count tabbibg.
            Assign("CountEntered", 0) ;reset the countentered
            $TabsToPress = GUICtrlRead($TabCount) ;read the number from the assembler GUI
            WinActivate($AssemblyWindow) ;activate assembly internet window
            $IE = _IEAttach($AssemblyWindow) ;attach selected window to IE process
            $PageLoadDone = _IELoadWait($IE) ;pause the script and returns 1 if done
            $IEObject = _IEGetObjByName($IE, "txtSearch") ;get object name to focus on
            _IEAction($IEObject, "focus") ;focus on the scan an item input
            For $i = 1 To $TabsToPress ;how many times to repeat the process below
                Send("{TAB}") ;switch to ALL of the next item in assembly
                Send("{SPACE}") ;press ALL of that item
            Next
            $HideCompleted = _IEGetObjByName($IE, "chkCompleted") ;check box with hide competed
            _IEAction($HideCompleted, "click") ;click hide completed
            GUICtrlSetData($TabCount, "")
            Assign("LimitWindowExisted", "No")
        EndIf

  If $CountEntered = 0 Then
            $IEAttach = _IEAttach($AssemblyWindow) ;attach IE
            $ID = _IEGetObjById($IEAttach, "lblItemData") ;get ID for the total lines of instruments in the list
            $Value = _IEPropertyGet($ID, "innertext") ;read the ID and get the number
            If $Value > 0 Then
                GUICtrlSetData($TabCount, $Value) ;assign number of lines into the assembler GUI so user wont have to.
                GUICtrlSetState($TabCount, $GUI_FOCUS);select all in case user manually enters the number by accident
                Assign("CountEntered", 1)
            EndIf
        EndIf

wend

 

This code crashes for random reasons while window never closes.
IE window does navigate here and there, but it never closes, yet at some random point, it seems to crash.

I do attach to the same window twice because i need to get lblItemData as well as to execute couontdown in the 1st If statement.

I am 100% sure it crashes somewhere in the second If statement   If $CountEntered = 0 Then but not sure why.

Once page is loaded again, it sometimes crashes sometimes does not.

Error is related either to _IEGetObjById (because there is an issue with the attached window or something) or _IEPropertyGet.

I will post the error once i see it, i someties see it right away sometimes it takes many many attempts doing exact same thing

 

Edited by tonycst

Share this post


Link to post
Share on other sites
DynamicRookie

The problem in your script is that you putted too long "If" statements in a While loop.

 

Avoid doing combined "If" statements and instead use "And" to make so.

Try adding a sleep Statement At the end of the script, to avoid it of crashing when loading, remember it does nearly 100 loops per second.

Share this post


Link to post
Share on other sites
mLipok

@tonycst try to read this:

How to post code on the forum *

and then edit your post.

Please read also:  How to use IE.au3  UDF with  AutoIt v3.3.14.x *

Question:

Which AutoIt Version you are using ?
Which exactly error code you get - or what you mean "crash" ?

 


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API Forum Rules *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library
 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2018-10-31

Share this post


Link to post
Share on other sites
tonycst
47 minutes ago, DynamicRookie said:

The problem in your script is that you putted too long "If" statements in a While loop.

 

Avoid doing combined "If" statements and instead use "And" to make so.

Try adding a sleep Statement At the end of the script, to avoid it of crashing when loading, remember it does nearly 100 loops per second.

I will look into AND, thanks.

Adding sleep is a NO NO. GUI does not seem to respond to me pressing buttons if there is a sleep in the loop.

yes there is a GUI in that loop, i just removed most of the code and just left the two that had IE in it.

Share this post


Link to post
Share on other sites
tonycst

 AutoIt Version: 3.3.14.1 if that helps.

I know how to post the code, thank you, i was in a hurry.

Question: How does AND help (before i tried using it) ?

Its just another condition that has to be meat.  (not exctly sure why i need AND here, i only check for 1 variable state, not two and it only one condition concerns me anyway)

thanks for reply.

Share this post


Link to post
Share on other sites
tonycst

Here is a simple way to replicate the problem i have using IE code.

;AutoIt Version: 3.3.14.1
#include <IE.au3>
$IEAttach = _IEAttach("MSN.com")
While 1
    $ID = _IEGetObjById($IEAttach, "sb_form_go")
    $Value = _IEPropertyGet($ID, "innertext") ;read the ID and get the number
    ConsoleWrite ($Value & @CRLF)
WEnd

When that window is CLOSED, or something in it changes (not sure exactly what and i am not talking about that particular page MSN.com, i was just using it as an example)
i get error in console saying

--> IE.au3 T3.0-2 Error from function _IEPropertyGet, $_IESTATUS_InvalidObjectType
0
"C:\Program Files (x86)\AutoIt3\Include\IE.au3" (1899) : ==> The requested action with this object has failed.:
If IsObj($oObject.document.getElementById($sID)) Then
If IsObj($oObject^ ERROR

That crashes the script.

If window is CHANGED (like went to another website) it DOES NOT crash but gives errors about which i dont really care but here they are.

0
--> IE.au3 T3.0-2 Warning from function _IEGetObjById, $_IESTATUS_NoMatch (sb_form_go)
--> IE.au3 T3.0-2 Error from function _IEPropertyGet, $_IESTATUS_InvalidDataType

Anyway to prevent the script from crash if window is closed ?

Adding If WinExists ($WinName) = 1 does not help, because window can disapear at the milisecond after it gets attached and right before _IEGetObjById() gets to read the attached window.

So how do i deal with that ?

 

Thanks !

I hope i posted this correctly this time :(

Edited by tonycst

Share this post


Link to post
Share on other sites
jdelaney
_IEErrorHandlerRegister

This will prevent the com exceptions.

#include <IE.au3>
_IEErrorHandlerRegister()
$oIE = _IECreate("google.com")
_IEQuit($oIE)
$oIE.document.getelementbyid('123')
ConsoleWrite("I'm still running!" & @CRLF)

output:

I'm still running!


IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites
tonycst
30 minutes ago, jdelaney said:
_IEErrorHandlerRegister

This will prevent the com exceptions.

#include <IE.au3>
_IEErrorHandlerRegister()
$oIE = _IECreate("google.com")
_IEQuit($oIE)
$oIE.document.getelementbyid('123')
ConsoleWrite("I'm still running!" & @CRLF)

output:

I'm still running!

YOU ARE THE MAN !

Am sure someone told me to do that before, but not in a straight forward way like you did.
Some people often reply with  "did you read post rules" and "did you read UDF post" etc and then give the answer, but for some reasons my brain is wired to ignore those and continue waiting for an answer from someone else.

Thanks allot.

:)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×