Jump to content
Sign in to follow this  
Chromwell

Problem with newest Autoit 3.3.8.1 - COM / SAP

Recommended Posts

Chromwell

With older Autoit Versions my script was working fine and i don´t know how i should change my script to work again...

Basically my problem section does nothing more then selecting some menus in SAP then pressing 2 buttons in following popup-windows and the 3rd popup is a file save dialog...

My script always stops executing after the 2nd button press (it is pressed, but it won´t get any further....)

Connection to SAP is initiated with _SAPSessAttach("") from the SAP UDF but the commands are sent directly via the COM interface to SAP.

_SAPSessAttach("")
ConsoleWrite("Setze $AnalyseBlatt ..." & @CRLF)
$AnalyseBlatt = @ScriptDir & "\test.xls"
ConsoleWrite("Lösche $AnalyseBlatt ..." & @CRLF)
If FileExists($AnalyseBlatt) Then
  FileDelete($AnalyseBlatt)
EndIf
$SAP_Session.findById("wnd[0]/shellcont[0]/shell/shellcont[2]/shell" ).expandNode("1000")
$SAP_Session.findById("wnd[0]/shellcont[0]/shell/shellcont[2]/shell" ).selectItem("4000", "COL01")
$SAP_Session.findById("wnd[0]/shellcont[0]/shell/shellcont[2]/shell" ).ensureVisibleHorizontalItem("4000", "COL01")
$SAP_Session.findById("wnd[0]/shellcont[0]/shell/shellcont[2]/shell" ).topNode = ("0001")
$SAP_Session.findById("wnd[0]/shellcont[0]/shell/shellcont[2]/shell" ).doubleClickItem("4000", "COL01")
ConsoleWrite("Btn0 Press..." & @CRLF)
$SAP_Session.findById("wnd[1]/tbar[0]/btn[0]").press
ConsoleWrite("Btn5 Press..." & @CRLF)
$SAP_Session.findById("wnd[1]/tbar[0]/btn[5]").press
;--------- SCRIPT STOPS HERE, without any error, it just hangs....
ConsoleWrite("Warte auf Speichern unter Dialog..." & @CRLF)
WinWait("Speichern unter")
ConsoleWrite("Setze Edit auf Analyseblatt..." & @CRLF)
ControlSetText("Speichern unter", "", "[CLASS:Edit; INSTANCE:1]", $AnalyseBlatt)
Sleep(2000)
ControlClick("Speichern unter", "", "[CLASS:Button; INSTANCE:2]")

Share this post


Link to post
Share on other sites
water

The script breaking changes section here describes that methods require paranthesis.

So maybe you have to change

$SAP_Session.findById("wnd[1]/tbar[0]/btn[0]").press
to
$SAP_Session.findById("wnd[1]/tbar[0]/btn[0]").press()

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
Chromwell

Even with this change the script halts after the btn5 press without any error ... when i cancel the file dialog that appears after the script pressed the button, the script goes on.

The same script runs smooth with autoit-v3.3.6.1. :)

Share this post


Link to post
Share on other sites
water

As you are working with objects to need to implement a COM error handler. Please check function ObjEvent. There you'll find an example.

After btn5 is pressed I would at least check the error code returned in @error and @extended.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
Chromwell

There´s no COM error, that´s the problem... the script just hangs after btn5 is pressed without an error... :)

I can´t even exit the script from the task-tray when it hangs after btn5 press ... it exits when i cancel the dialog in SAP that comes after it pressed the btn5...

#include <../include/SAP.au3>
#include <IE.au3>
_IEErrorHandlerRegister ("MyErrFunc")

_test()
func _test()
_SAPSessAttach("")
ConsoleWrite("Setze $AnalyseBlatt ..." & @CRLF)
$AnalyseBlatt = @ScriptDir & "test.xls"
ConsoleWrite("Lösche $AnalyseBlatt ..." & @CRLF)

If FileExists($AnalyseBlatt) Then
FileDelete($AnalyseBlatt)
EndIf

$SAP_Session.findById("wnd[0]/shellcont[0]/shell/shellcont[2]/shell" ).expandNode("1000")
$SAP_Session.findById("wnd[0]/shellcont[0]/shell/shellcont[2]/shell" ).selectItem("4000", "COL01")
$SAP_Session.findById("wnd[0]/shellcont[0]/shell/shellcont[2]/shell" ).ensureVisibleHorizontalItem("4000", "COL01")
$SAP_Session.findById("wnd[0]/shellcont[0]/shell/shellcont[2]/shell" ).topNode = ("0001")
$SAP_Session.findById("wnd[0]/shellcont[0]/shell/shellcont[2]/shell" ).doubleClickItem("4000", "COL01")

ConsoleWrite("Btn0 Press..." & @CRLF)
$SAP_Session.findById("wnd[1]/tbar[0]/btn[0]").press()
ConsoleWrite("Btn5 Press..." & @CRLF)
$SAP_Session.findById("wnd[1]/tbar[0]/btn[5]").press()

;--------- SCRIPT STOPS HERE, without any error, it just hangs....

ConsoleWrite("Warte auf Speichern unter Dialog..." & @CRLF)
WinWait("Speichern unter")
ConsoleWrite("Setze Edit auf Analyseblatt..." & @CRLF)
ControlSetText("Speichern unter", "", "[CLASS:Edit; INSTANCE:1]", $AnalyseBlatt)
Sleep(2000)
ControlClick("Speichern unter", "", "[CLASS:Button; INSTANCE:2]")

EndFunc

Func MyErrFunc()
    ; Important: the error object variable MUST be named $oIEErrorHandler
    $ErrorScriptline = $oIEErrorHandler.scriptline
    $ErrorNumber = $oIEErrorHandler.number
    $ErrorNumberHex = Hex($oIEErrorHandler.number, 8)
    $ErrorDescription = StringStripWS($oIEErrorHandler.description, 2)
    $ErrorWinDescription = StringStripWS($oIEErrorHandler.WinDescription, 2)
    $ErrorSource = $oIEErrorHandler.Source
    $ErrorHelpFile = $oIEErrorHandler.HelpFile
    $ErrorHelpContext = $oIEErrorHandler.HelpContext
    $ErrorLastDllError = $oIEErrorHandler.LastDllError
    $ErrorOutput = ""
    $ErrorOutput &= "--> COM Error Encountered in " & @ScriptName & @CR
    $ErrorOutput &= "----> $ErrorScriptline = " & $ErrorScriptline & @CR
    $ErrorOutput &= "----> $ErrorNumberHex = " & $ErrorNumberHex & @CR
    $ErrorOutput &= "----> $ErrorNumber = " & $ErrorNumber & @CR
    $ErrorOutput &= "----> $ErrorWinDescription = " & $ErrorWinDescription & @CR
    $ErrorOutput &= "----> $ErrorDescription = " & $ErrorDescription & @CR
    $ErrorOutput &= "----> $ErrorSource = " & $ErrorSource & @CR
    $ErrorOutput &= "----> $ErrorHelpFile = " & $ErrorHelpFile & @CR
    $ErrorOutput &= "----> $ErrorHelpContext = " & $ErrorHelpContext & @CR
    $ErrorOutput &= "----> $ErrorLastDllError = " & $ErrorLastDllError
    MsgBox(0,"COM Error", $ErrorOutput)
    SetError(1)
    Return
EndFunc  ;==>MyErrFunc
Edited by Chromwell

Share this post


Link to post
Share on other sites
water

I inserted some more error checking an simplified the COM error handler. Could you please give it a try?

Global $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")

_test()

Func _test()
    _SAPSessAttach("")
    ConsoleWrite("Setze $AnalyseBlatt ..." & @CRLF)
    $AnalyseBlatt = @ScriptDir & "test.xls"
    ConsoleWrite("Lösche $AnalyseBlatt ..." & @CRLF)

    If FileExists($AnalyseBlatt) Then
        FileDelete($AnalyseBlatt)
    EndIf

    $SAP_Session.findById("wnd[0]/shellcont[0]/shell/shellcont[2]/shell").expandNode("1000")
    ConsoleWrite("Result of 1st findByID...: " & @error & "-" & @extended & @CRLF)
    $SAP_Session.findById("wnd[0]/shellcont[0]/shell/shellcont[2]/shell").selectItem("4000", "COL01")
    ConsoleWrite("Result of 2nd findByID...: " & @error & "-" & @extended & @CRLF)
    $SAP_Session.findById("wnd[0]/shellcont[0]/shell/shellcont[2]/shell").ensureVisibleHorizontalItem("4000", "COL01")
    ConsoleWrite("Result of 3rd findByID...: " & @error & "-" & @extended & @CRLF)
    $SAP_Session.findById("wnd[0]/shellcont[0]/shell/shellcont[2]/shell").topNode = ("0001")
    ConsoleWrite("Result of 4th findByID...: " & @error & "-" & @extended & @CRLF)
    $SAP_Session.findById("wnd[0]/shellcont[0]/shell/shellcont[2]/shell").doubleClickItem("4000", "COL01")
    ConsoleWrite("Result of 5th findByID...: " & @error & "-" & @extended & @CRLF)

    ConsoleWrite("Btn0 Press..." & @CRLF)
    $SAP_Session.findById("wnd[1]/tbar[0]/btn[0]").press()
    ConsoleWrite("Result of Btn0 Press...: " & @error & "-" & @extended & @CRLF)
    ConsoleWrite("Btn5 Press..." & @CRLF)
    $SAP_Session.findById("wnd[1]/tbar[0]/btn[5]").press()
    ConsoleWrite("Result of Btn5 Press...: " & @error & "-" & @extended & @CRLF)

    ;--------- SCRIPT STOPS HERE, without any error, it just hangs....

    ConsoleWrite("Warte auf Speichern unter Dialog..." & @CRLF)
    WinWait("Speichern unter")
    ConsoleWrite("Setze Edit auf Analyseblatt..." & @CRLF)
    ControlSetText("Speichern unter", "", "[CLASS:Edit; INSTANCE:1]", $AnalyseBlatt)
    Sleep(2000)
    ControlClick("Speichern unter", "", "[CLASS:Button; INSTANCE:2]")

EndFunc   ;==>_test

; User's COM error function. Will be called if COM error occurs
Func _ErrFunc($oError)
    ; Do anything here.
    ConsoleWrite("err.number is: " & @TAB & $oError.number & @CRLF & _
            "err.windescription:" & @TAB & $oError.windescription & @CRLF & _
            "err.description is: " & @TAB & $oError.description & @CRLF & _
            "err.source is: " & @TAB & $oError.source & @CRLF & _
            "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
            "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
            "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
            "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
            "err.retcode is: " & @TAB & $oError.retcode & @CRLF & @CRLF)
EndFunc   ;==>_ErrFunc

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
Chromwell

Here are the outputs from scite... script hangs on new autoit... :)

Old Autoit:

>Running:(3.3.6.1):C:\Program Files\AutoIt3\autoit3.exe "H:\AutoIT\Projects\CQTS EACDX\crap.au3"  
Setze $AnalyseBlatt ...
Lösche $AnalyseBlatt ...
Result of 1st findByID...: 0-0
Result of 2nd findByID...: 0-0
Result of 3rd findByID...: 0-0
Result of 4th findByID...: 0-0
Result of 5th findByID...: 0-0
Btn0 Press...
Result of Btn0 Press...: 0-0
Btn5 Press...
Result of Btn5 Press...: 0-0
Warte auf Speichern unter Dialog...
Setze Edit auf Analyseblatt...
+>11:57:41 AutoIT3.exe ended.rc:0
>Exit code: 0   Time: 7.160

New Autoit:

>Running:(3.3.8.1):C:\Program Files (x86)\AutoIt3\autoit3.exe "H:\AutoIT\Projects\CQTS EACDX\crap.au3"
Setze $AnalyseBlatt ...
Lösche $AnalyseBlatt ...
Result of 1st findByID...: 0-0
Result of 2nd findByID...: 0-0
Result of 3rd findByID...: 0-0
Result of 4th findByID...: 0-0
Result of 5th findByID...: 0-0
Btn0 Press...
Result of Btn0 Press...: 0-0
Btn5 Press...

Share this post


Link to post
Share on other sites
water

Looks like a bug. Problem is that the Devs need a skript to reproduce the problem. Unfortunately not every of them has SAP available.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
Chromwell

Ok, thanks for your effort water!

Perhaps i can reproduce it in an other application and i can submit a bug report or so... :)

Share this post


Link to post
Share on other sites
water

I checked Trac #2056 and maybe there was a similar problem with Excel.

I don't know when the first Beata will be released but a the moment I would stick with 3.3.6.1 in your case.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
StSchnell

Hello water,

Chromwell is right, it seems to be a problem with the new AutoIt version. Check with the following program

;-Begin-----------------------------------------------------------------
  $oDia = ObjCreate("COMDialog")
  If IsObj($oDia) Then
 
    $Result = 0
   
    While $Result <> 1
 
      $Result = $oDia.WindowEvent()
   
      Select
        Case $Result = 1
          MsgBox(0, "Dialog", "Ende")
        Case $Result = 2
          MsgBox(0, "Dialog", "Test1 Button betätigt")
        Case $Result = 3
          MsgBox(0, "Dialog", "Test2 Button betätigt")
      EndSelect
     
    Wend
  EndIf
;-End-------------------------------------------------------------------

with this ActiveX DLL http://www.stschnell.de/temp/COMDialog.zip, it is one of my test libraries. It shows only a dialog with two buttons and the event loop of the AutoIt program catches the message. It works perfect with 3.3.6.1 but it crashes with the actual version.

Cheers

Stefan

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  

  • Similar Content

    • JNutt
      By JNutt
      I see $hWnd used as a local variable in a lot of script examples.  I know the 'h' is used for handles, but what is the 'Wnd' short for?
      Thanks!
    • watchoverme
      By watchoverme
      hi all, how can i move mouse to the place where pixel changes
       
      While Sleep (3000)
      $pix = PixelChecksum(0,0,55,55)
      If IsArray($pix) = True Then
      MouseMove($pix [0],$pix[1])
      EndIf
      WEnd
    • Fenzik
      By Fenzik
       Hello all"
      I have curious problem with com object implementation of Sapi 5.1.
      In some cases }Some Voice engines] the metods for retrieve the voice parameters fails with error :Member not exists:.
      But the Retrieved Voice object can speak the given text, so It exists and work.
      Example of this type of Engine can be this one: http://download.kobavision.be/KobaSpeech3/KobaSpeech 3 With Vocalizer Serena - English (Great Britain).exe (can work as demo)
      So my question is> Is there some way to workaround or solve this issue?
      What i tryed:
      1. Typical use of Sapi.spvoice object:
      $oMyError = ObjEvent("AutoIt.Error","MyErrFunc"); Install a custom error handler
       
        $spvoice = ObjCreate("sapi.spvoice")
      for $voice in $spvoice.getvoices()
        msgbox(0, "Voice", $voice.getdescription())
      next
      Func MyErrFunc()
      $HexNumber = hex($oMyError.number, 8)
      Msgbox(0,"","We intercepted a COM Error !" & @CRLF &"Number is: " & $HexNumber & @CRLF &"Windescription is: " & $oMyError.windescription)
      SetError(1)
      Endfunc

      2. Implement workaround based on Nvda Screen reader sapi5 Library at https://github.com/nvaccess/nvda/blob/master/source/synthDrivers/sapi5.py
      Thys code in Pascal should work, so i tryed to reproduce it in Autoit.
      Pascal code just as example:
                   SOTokens:=SpVoice.GetVoices('','');
                   for i:=0 to SOTokens.Count-1 do
                   try
                        SOToken:=SOTokens.Item(I); s:=SOToken.GetDescription(0);
      end
      In Autoit I tryed it like this:
      $oMyError = ObjEvent("AutoIt.Error","MyErrFunc"); Install a custom error handler
        $spvoice = ObjCreate("sapi.spvoice")
      for $i = 0 to $spvoice.getvoices.count-1
      $name = $spvoice.getvoices.item($i).getdescription
      msgbox(0,"Voice", $name)
      next
      Func MyErrFunc()
      $HexNumber = hex($oMyError.number, 8)
      Msgbox(0,"","We intercepted a COM Error !" & @CRLF &"Number is: " & $HexNumber & @CRLF &"Windescription is: " & $oMyError.windescription)
      SetError(1)
      Endfunc
      Both of this methods returning same Error ("Member not exists.").
      Thanks a lot for help.
      Znefyg
    • Ignacio
      By Ignacio
      Hello, and good day
      Im trying to make a sentence autocompleter so that when you type certain words (or commands) the scripts, and im in need of help/pointers
      That is what i have at the time and the issues i have currently is that:
      - I cant find an easy way to reset the counter to 0 in case a different letter from those are pressed ( tried NOT _ispressed but i think i got it wrong)
      -Is there another way to detect the key press that _ispressed? (i couldnt find it so far), since i feel like it is too clunky ( although maybe that is just me and my way to code)
      - for some reason the hex code (6F) for the / (divide nume pad) isnt working for me
       
      Im thinking of making a text file with some words to use them as variables/comparations  (so that at least removes the need of a variable for the words in the script) and make the script make a temporal text file to save the input and then compare it with the other one. But i dont know if that is a good approach.
      Thanks for your time and patience.
    • gillesg
      By gillesg
      Hello,
       
      Is there a way to get all the properties and method of a COM object thru Autoit.
      I am looking in a way of display the imbricated structure of object and method.
       
      Example of COm objects are "itunes.application", "Shell.application" and so on.
      The idea is to have a code looking like
      $objtobrowse = objcreate("itunes.application") if isobj($objtobrowse) then $colItems = $objtobrowse.buildinproperty For $objItem In $colItems ConsoleWrite($objItem.<Name> & " - " & $objItem.<Value> & @CRLF) Next EndIf  
×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.