Jump to content

Problem with newest Autoit 3.3.8.1 - COM / SAP


Recommended Posts

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]")
Link to comment
Share on other sites

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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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...
Link to comment
Share on other sites

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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • 3 months later...

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

Link to comment
Share on other sites

  • 1 year later...

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
 Share

×
×
  • Create New...