Jump to content
Sign in to follow this  
Steveiwonder

_IE_ performance issues.

Recommended Posts

Steveiwonder

Hello,

There has been some problems with my script and it seems to be this part of the code that takes a long time rougly 2-4mins, there is quite alot here so please forgive me.

I have made a comment within the code to advise when the slowness begins.

NOTE: I'm not asking anyone to test the code just take a look and tell me if there is an apparent that your trained eye can see?

Func DoStuff()
    ConsoleWrite("Waiting for IE to load then will ""DO STUFF""" & @CRLF)
    _IELoadWait($oIE)
    ConsoleWrite("IE has now loaded, gonna ""DO STUFF""" & @CRLF)
    ;***************************************** SLOWNESS STARTS HERE
    $o_form = _IEFormGetObjByName ($oIE, "frmCase") ; sets form
    If @error Then
        Fail("Unable to find form ""frmCase""")
    EndIf

    $o_Title = _IEFormElementGetObjByName($o_form, "title") ;sets inputbox "title"
    If @error Then
        Fail("Unable to find input ""title""")
    EndIf

    $o_CircuitID = _IEFormElementGetObjByName($o_form, "circuitID") ;sets inputbox "circuitID"
    If @error Then
        Fail("Unable to find input ""circuitID""")
    EndIf

    $o_Notes = _IEFormElementGetObjByName($o_form, "notes") ; sets textarea "notes"
    If @error Then
        Fail("Unable to find textarea ""notes""")
    EndIf

    $o_CaseType = _IEFormElementGetObjByName($o_form, "case_type") ;sets the select "case_type"
    If @error Then
        Fail("Unable to find select ""case_type""")
    EndIf

    $o_CustCalledCHK = _IEFormElementGetObjByName($o_form, "chkCustomerCalled") ; sets the Check box "chkCustomerCalled"
    If @error Then
        Fail("Unable to find checkbox ""chkCustomerCalled""")
    EndIf

    $o_ProductCat = _IEFormElementGetObjByName($o_form, "prod_cat") ;sets the select "prod_cat"
    If @error Then
        Fail("Unable to find select ""prod_cat""")
    EndIf

    $o_QueryDays = _IEFormElementGetObjByName($o_form, "query_days") ;sets the select "query_days"
    If @error Then
        Fail("Unable to find select ""query_days""")
    EndIf

    $o_QueryType = _IEFormElementGetObjByName($o_form, "query_type") ;sets the select "query_type"
    If @error Then
        Fail("Unable to find select ""query_type""")
    EndIf

    $oPrevCaseFrame = _IEFrameGetObjByName($oIE, "prev_cases") ; sets the frame "prev_cases"
    If @error Then
        Fail("Unable to find frame ""prev_cases""")
    EndIf
    ConsoleWrite("_IEFormElementGetObJByName ALL COMPLETE - ALL OBJECT GOTTEN" & @CRLF)
    
    $circuit = _IEFormElementGetValue($o_circuitID) ; gets value from the "circuitID" inputbox
    ConsoleWrite("Got circuit ID Value" & @CRLF)
    
    ;set/select/check values on webpage
    _IEFormElementSetValue($o_Title, $circuit & " - ") ; sets the "title" input box to "Circuit ID - "
    _IEFormElementSetValue($o_Notes, $Q) ; sets the "notes" text area value to what ever $Q holds
    _IEFormElementSetValue($o_QueryDays, "90") ;sets the "query_days" input box to "90"
    
    ConsoleWrite("Set Title, notes and Query days" & @CRLF)
    _IEFormElementOptionselect($o_CaseType, "Cus. Serv. Rprt Prob", 1, "byValue"); sets the select called "case_type" to "Cus.Serv. Rprt Prob" VALUE hidden property of element)
    _IEFormElementOptionselect($o_ProductCat, "Service Offerings", 1, "byValue") ; sets the select called "prod_cat" to "Service Offerings" VALUE hidden property of element)
    _IEFormElementOptionselect($o_QueryType, "circuitID", 1, "byValue") ; sets the select called "query_type" to "circuitID" (to search prev case history on the circuit ID)
    
    ConsoleWrite("Set All options" & @CRLF)
    _IEFormElementCheckBoxSelect($o_form, "", "chkCustomerCalled", 1, "byIndex") ; sets the check box to a "checked" state.
    
    ConsoleWrite("Retreiving Case History, please wait..." & @CRLF)
    _IELinkClickByText($oIE, "Find") ; load prev case history
    _IELoadWait($oPrevCaseFrame) ; wait for load
    ConsoleWrite("Got Case History..." & @CRLF)
    ;;;;;;;;;;
    ; Get current text from "NOTES" TEXTAREA. Insert that & "Previous Case History" into notes.
    _IEFormElementSetValue($o_Notes, _IEFormElementGetValue($o_Notes) & @CRLF & "Previous Case History")

    $history = _IEPropertyGet($oPrevCaseFrame, "innertext") ; gets any Previous Case History avilable as text/String
    $TableHeaderstoRemove = "Case IDCreate DateConditionStatusTitleVendor NameTrouble Sub RegionEquipment ProviderEquipment" ; Table headers need to be removed from string

    $history = StringReplace($history, $TableHeaderstoRemove, "") ; Removing table headers

    $history = StringSplit($history, @CRLF) ; Split the string into array at every line break

    For $cases in $history
        ;ConsoleWrite($cases & @CRLF & @CRLF)
        If StringLen($cases) >6 Then ; not some random empty element in the array or some misfit String
            _IEFormElementSetValue($o_Notes, _IEFormElementGetValue($o_Notes) & @CRLF & $cases)
            If StringInStr($cases, "open") Then ; the states will be in the string
                Msgbox(64+262144, "Possible Case Already Open", "Cases History Checked, a possible open case has been found. Please confirm this before creating a duplicate ticket")
            EndIf
        EndIf
    Next

EndFunc

Thanks alot.

Steve

Edited by Steveiwonder

They call me MrRegExpMan

Share this post


Link to post
Share on other sites
Steveiwonder

Ok,

after going through everything it seems all of the

_IEFormGetObjByName()
or
_IEFormElementGetValue()
are causing the slowness. Each of them are taking 5-15 seconds.

Anyone have any idea why? or an alternative?

Edited by Steveiwonder

They call me MrRegExpMan

Share this post


Link to post
Share on other sites
PsaltyDS

after going through everything it seems all of the

_IEFormGetObjByName()
or
_IEFormElementGetValue()
are causing the slowness. Each of them are taking 5-15 seconds.
That seems really unlikely. How did you determine that?

:mellow:


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

Share this post


Link to post
Share on other sites
Steveiwonder

That seems really unlikely. How did you determine that?

:mellow:

just by placing Alot of ConsoleWrites in like this...

ConsoleWrite("Getting frmCase" & @CRLF)
$o_form = _IEFormGetObjByName ($oIE, "frmCase") ; sets form
ConsoleWrite("Got frmcase... " & @CRLF)
    If @error Then
        Fail("Unable to find form ""frmCase""")
    EndIf

and watching when they display in the console. I did this for each line of code.

And i always see ConsoleWrite("Getting frmCase" & @CRLF) then its a pause for like 5-15 seconds.

Steveiwonder

Edited by Steveiwonder

They call me MrRegExpMan

Share this post


Link to post
Share on other sites
PsaltyDS

I've never seen _IE* functions take that long just to find a DOM element. For example, this takes about 90 milliseconds:

#Include <IE.au3>

Global $sURL = "http://www.google.com"
Global $oIE = _IECreate($sURL)
Global $iTimer, $oForm

$iTimer = TimerInit()
$oForm = _IEFormGetObjByName($oIE, "f")
$iTimer = TimerDiff($iTimer)
If IsObj($oForm) Then
    ConsoleWrite("Name = " & $oForm.Name & "; Time = " & Round($iTimer / 1000, 3) & "sec" & @LF)
Else
    ConsoleWrite("Error getting form." & @LF)
EndIf

Note that $oForm is tested with IsObj(). Your error testing won't work because @error has been reset by ConsoleWrite() before you tested it. Try the above script, and then try it with your URL.

:mellow:


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

Share this post


Link to post
Share on other sites
Steveiwonder

Think i found the issue

$oIE inside doStuff() was being set by another function.

However, $oIE was not being set to a Global var .. so it looked like this.

Local $oIE 

;example functions - Shortend down but still gives the same result.

Func DoStuff()
   $o_form = _IEFormGetObjByName ($oIE, "frmCase") ; sets form
EndFunc

Func WaitForWindow()
   
   $title = "Title"
   WinWait($title)
   $oIE = _IEAttach($title)
   Return
EndFunc

I've change Local $oIE to Global $oIE and its seems to of worked?

No idea how this made it "slower" as i would of though it wouldn't work all together.

p.s. thanks for your PsaltyDS

Edited by Steveiwonder

They call me MrRegExpMan

Share this post


Link to post
Share on other sites
PsaltyDS

p.s. thanks for your PsaltyDS

Ooh, I'm a helpful verb now!

:mellow:


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

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
Sign in to follow this  

×