Sign in to follow this  
Followers 0
TripScott

AutoIt and SAP without scripting available

13 posts in this topic

Hello.

I am new to AutoIt. I have created a script that goes to SAP and navigates to a screen that creates a file. When the file has been created, SAP pops up a window that states the file was created. At this point I need AutoIt to wait until the "Information" pop-up appears and then Send("{Esc}") or Send("{Enter}") to close the window. AutoIt isn't recognizing this "Information" window. I have used the WindowId program to get information about the window and used variations of WinActivate by Window Title (Information), by class, classNN, window coordinates and mouse coordinates. It pauses at this point.

My company has not turned on the SAP scripting. I am going to start asking for it, but I doubt it will happen.

Can anyone help me with this problem? I have to demo this script on Thursday to my group of 30. I would like to have it fully working by then. It would really boost my job and possibly keep me off the lay off list.

Thanks,

Trip

Share this post


Link to post
Share on other sites



Welcome to the forum.

> ... I need AutoIt to wait until the "Information" pop-up appears ...

Did you try WinWait?

> ... used variations of WinActivate ...

Did you mean WinWait?

> ... It pauses at this point.

I'm confused - but look at where I'm from :-)

> I am new to AutoIt.

> I have to demo this script on Thursday to my group of 30.

Are you crazy? :-)


[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

Welcome TripScott,

Could you post screenshots of the window coming from SAP? Could you also post a screenshot of you using the AutoIt Window Info tool on the SAP window? And possibly the information of the AutoIt Window Info tool, as well.

This will help us help you a lot better than we currently can. Since you said you are showing this to a group of people on thursday, I think this is rather important.

Regards,

Manadar

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Thank you for you willingness to help me out. I really, really appreciate it. I was writing from home & didn't have my code or the program so I probably stated some code wrong.

This is the code telling AutoIt to wait until the Information window pops up. I attached a screen shot of the information window as well.

; Close Information window

WinWait("[TITLE:Information; CLASS:#32770]", "")

If Not WinActive("[TITLE:Information; CLASS:#32770]", "") Then WinActivate("[TITLE:Information; CLASS:#32770]", "")

WinWaitActive("[TITLE:Information; CLASS:#32770]", "")

WinClose(0x00020AC4)

I also tried these instead of WinClose. They didn't work either.

;Send("{esc}")

;ControlClick("[[TITLE:Information; CLASS:#32770]", "", "[CLASS:Button; INSTANCE:2]", "left", 1, 10, 14)

This is what the Window Info shows when I put the finder tool on the checkmark button.

>>>> Window <<<<

Title: Information

Class: #32770

Position: 73, 407

Size: 436, 131

Style: 0x96080044

ExStyle: 0x00010010

Handle: 0x0007096E

>>>> Control <<<<

Class: Button

Instance: 2

ClassnameNN: Button2

Advanced (Class): [CLASS:Button; INSTANCE:2]

ID: 111

Text:

Position: 9, 81

Size: 20, 21

ControlClick Coords: 7, 9

Style: 0x5000000B

ExStyle: 0x00000000

Handle: 0x0001097A

>>>> Mouse <<<<

Position: 18, 111

Cursor ID: 0

Color: 0xAEAEAE

>>>> StatusBar <<<<

>>>> Visible Text <<<<

>>>> Hidden Text <<<<

Lastly,

>> I am new to AutoIt.

>> I have to demo this script on Thursday to my group of 30.

>Are you crazy? :-)

Yes. My boss asked me to do this. And considering we just had 100 people laid off, I think I should do it. If this isn't working by then I will manually click the button. They wouldn't know it. But it would be nice to have it working.

Thanks again,

Trip

post-45507-1235395676_thumb.jpg

Edited by TripScott

Share this post


Link to post
Share on other sites

Well, in this code I see an important problem on the last line:

; Close Information window
WinWait("[TITLE:Information; CLASS:#32770]", "")
If Not WinActive("[TITLE:Information; CLASS:#32770]", "") Then WinActivate("[TITLE:Information; CLASS:#32770]", "")
WinWaitActive("[TITLE:Information; CLASS:#32770]", "")
WinClose(0x00020AC4)       ; <== Based on the actual window handle, this changes each time. So you must also use the text match here.oÝ÷ Ù8b²+zÛ^­«­¢+Ù]¥¹]¥Ð ÅÕ½ÐímQ%Q1é%¹½ÉµÑ¥½¸ì
1MLèÌÈÜÜÁtÅÕ½Ðì°ÅÕ½ÐìÅÕ½Ðì¤(ÀÌØí¡]¹ô]¥¹Ñ!¹± ÅÕ½ÐímQ%Q1é%¹½ÉµÑ¥½¸ì
1MLèÌÈÜÜÁtÅÕ½Ðì¤)%9½Ð]¥¹Ñ¥Ù ÀÌØí¡]¹°ÅÕ½ÐìÅÕ½Ðì¤Q¡¸]¥¹Ñ¥ÙÑ ÀÌØí¡]¹°ÅÕ½ÐìÅÕ½Ðì¤ì¹½Ðɱ±äÉÅÕ¥É)]¥¹]¥ÑÑ¥Ù ÀÌØí¡]¹°ÅÕ½ÐìÅÕ½Ðì¤ì¹½Ðɱ±äÉÅÕ¥É)]¥¹
±½Í ÀÌØí¡]¹¤oÝ÷ Ø  Ý{azaz·(u쨺ƢuØmÂä"Ƕ¬zºè­«­¢+Ù
½¹Ñɽ±
±¥¬ ÅÕ½ÐímÕuml½ÕumQ%Q1é%¹½ÉµÑ¥½¸ì
1MLèÌÈÜÜÁtÅÕ½Ðì°ÅÕ½ÐìÅÕ½Ðì°ÅÕ½Ðím
1MLé   ÕÑѽ¸ì%9MQ9
èÉtÅÕ½Ðì°ÅÕ½Ðí±ÐÅÕ½Ðì°Ä°ÄÀ°ÄÐ

In either case, make sure you declare:

Opt("WinTitleMatchMode", 4)

Or ...

AutoItSetOption("WinTitleMatchMode", 4)

If the above code doesn't work, then your way to match the window maybe is too strict. Try to see if you can just use the title only: WinWait("Information") and WinGetHandle("Information")

Share this post


Link to post
Share on other sites

Manadar,

Thank you for your reply. I put in your code and it did the same thing. All I really need is to have Enter sent, but when I use this code, it doesn't work. I just pauses. When I manually press Enter the script continues.

If Not WinActive($hWnd, "") Then WinActivate($hWnd, "") ; not really required

WinWaitActive($hWnd, "") ; not really required

WinClose($hWnd)

ControlClick("[TITLE:Information; CLASS:#32770]", "", "[CLASS:Button; INSTANCE:2]", "left", 1, 10, 14)

So I put in this code:

If Not WinActive($hWnd, "") Then WinActivate($hWnd, "") ; not really required

WinWaitActive($hWnd, "") ; not really required

WinClose($hWnd)

ControlClick("[TITLE:Information; CLASS:#32770]", "", "[CLASS:Button; INSTANCE:2]", "left", 1, 10, 14)

The result to this was the SAP application closed all together. It is like AutoIt isn't seeing the pop-up or not putting the focus on the pop-up.

Any ideas?

Trip

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

This sort of behaviour is exactly why using non-standard controls is a bad idea. Way to go SAP.

It is good to know that the SAP window is now closing. The main application probably detects the WM_CLOSE message on the child window (the message). This means that AutoIt can at least see the window and is aware of it. This usually means interaction is possible in some way.

You could try sending the {ENTER} key to the application in general, by not specifying a ControlID at all. Like so:

ConsolSend("[TITLE:Information; CLASS:#32770]","","","{ENTER}")

Or try:

ConsolSend("[TITLE:Information; CLASS:#32770]","","[CLASS:Button; INSTANCE:2]","{ENTER}")

Otherwise, maybe you could loop through the available controls in a window. I have never done this myself, but it might just work.

http://www.autoitscript.com/forum/index.ph...st&p=556293

Automation behavior of windows and controls like this is always a very challenging task. It is never predictable, and very often you have to grab all the resources you can.

Edited by Manadar

Share this post


Link to post
Share on other sites

It Worked!!!

I used

ControlSend("[TITLE:Information; CLASS:#32770]","","","{ENTER}")

Thank you so much! My document creation for my team is now going to take about 8 seconds instead of 6 minutes per document.

Trip

Share this post


Link to post
Share on other sites

It Worked!!!

I used

ControlSend("[TITLE:Information; CLASS:#32770]","","","{ENTER}")

Thank you so much! My document creation for my team is now going to take about 8 seconds instead of 6 minutes per document.

Trip

Great to hear, Trip!

I am very pleased with the fact you have gotten it working, well before Thursday as well.

I hope I have saved you some headaches and sleepless nights. ;]

Manadar

Share this post


Link to post
Share on other sites

I have using this "fixed" code for the last week and my demo went GREAT! But, the code runs inconsistantly and I don't know why. It is an issue around line 42 until the close information window. Somestimes it will enter $myClip twice. Or on the next screen (yes, there really are two screens called "BOM Report Selection - Single Assembly" with the same exact window information) it will skip the 1st click control. Am I missing something in my code?

Thank you for any help. Trip

CODE
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****

#AutoIt3Wrapper_outfile=..\ZCS0 rpt.exe

#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <Word.au3>

#include <WinAPI.au3>

Opt("WinWaitDelay", 100)

Opt("WinTitleMatchMode", 4)

Opt("WinDetectHiddenText", 1)

Opt("MouseCoordMode", 0)

dim $hWnd, $myClip

HotKeySet("{ESC}", "Quit");This will trigger an exit

; open access & goto main screen

If Not WinActive("SAP Easy Access") Then WinActivate("[CLASS:SAP_FRONTEND_SESSION]")

If Not WinActive("[CLASS:SAP_FRONTEND_SESSION]") Then MsgBox(0, "Not Open", "SAP is not open. Log into SAP and try again.")

If Not WinActive("[CLASS:SAP_FRONTEND_SESSION]") Then ClipPut("SAP CLOSED")

If Not WinActive("[CLASS:SAP_FRONTEND_SESSION]") Then Exit

Do

Send("{f3}")

Until WinActive("SAP Easy Access")

;select control field

ControlCommand("[CLASS:SAP_FRONTEND_SESSION]", "", "Edit1", "editpaste", "ZCS0")

; Press checkmark button

ControlClick("SAP Easy Access", "", "[iD:59392]", "left", 1, 19, 15)

WinWait("BOM Reports for Engr. Documents (ZCS0)", "")

If Not WinActive("BOM Reports for Engr. Documents (ZCS0)", "") Then WinActivate("BOM Reports for Engr. Documents (ZCS0)", "")

WinWaitActive("BOM Reports for Engr. Documents (ZCS0)", "")

; Select the Single Asm report

ControlClick("BOM Reports for Engr. Documents (ZCS0)", "", "[iD:100]", "left", 1, 101, 103)

Send("{ENTER}")

WinWait("BOM Report Selection - Single Assembly", "")

If Not WinActive("BOM Report Selection - Single Assembly", "") Then WinActivate("BOM Report Selection - Single Assembly", "")

WinWaitActive("BOM Report Selection - Single Assembly", "")

; paste part number in field

;Send("{CTRLDOWN}v{CTRLUP}{ENTER}")

;ver 2: does field have an entry

$myClip = ClipGet()

Send($myClip & "{ENTER}")

WinWait("BOM Report Selection - Single Assembly", "")

If Not WinActive("BOM Report Selection - Single Assembly", "") Then WinActivate("BOM Report Selection - Single Assembly", "")

WinWaitActive("BOM Report Selection - Single Assembly", "")

ControlClick("BOM Report Selection - Single Assembly", "", "[iD:100]", "left", 1, 24, 353)

send("{tab}{end}")

;ControlClick("BOM Report Selection - Single Assembly", "", "[iD:400]", "left", 1, 360, 353)

Send($myClip & "{ENTER}")

; Close Information window

WinWait("[TITLE:Information; CLASS:#32770]", "")

$hWnd = WinGetHandle("[TITLE:Information; CLASS:#32770]")

ControlGetFocus("[TITLE:Information; CLASS:#32770]")

ControlSend ("[TITLE:Information; CLASS:#32770]","","","{ENTER}")

If Not WinActive("SAP Easy Access") Then WinActivate("[CLASS:SAP_FRONTEND_SESSION]")

Do

Send("{f3}")

Until WinActive("SAP Easy Access")

WinWait("[REGEXPTITLE:^.* - Microsoft Word$]", "")

If Not WinActive("[REGEXPTITLE:^.* - Microsoft Word$]", "") Then WinActivate("[REGEXPTITLE:^.* - Microsoft Word$]", "")

WinWaitActive("[REGEXPTITLE:^.* - Microsoft Word$]", "")

Func Quit()

Exit 0

EndFunc

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

The problem lies probably in having two screens with the same title and not managing them entirely correct. Please have a look at the comments I have made in your code:

Around line 42~65 as you suggested.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=..\ZCS0 rpt.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <Word.au3>
#include <WinAPI.au3>

Opt("WinWaitDelay", 100)
Opt("WinTitleMatchMode", 4)
Opt("WinDetectHiddenText", 1)
Opt("MouseCoordMode", 0)


Dim $hWnd, $myClip
HotKeySet("{ESC}", "Quit");This will trigger an exit

; open access & goto main screen
If Not WinActive("SAP Easy Access") Then WinActivate("[CLASS:SAP_FRONTEND_SESSION]")
If Not WinActive("[CLASS:SAP_FRONTEND_SESSION]") Then MsgBox(0, "Not Open", "SAP is not open. Log into SAP and try again.")
If Not WinActive("[CLASS:SAP_FRONTEND_SESSION]") Then ClipPut("SAP CLOSED")
If Not WinActive("[CLASS:SAP_FRONTEND_SESSION]") Then Exit
Do
    Send("{f3}")
Until WinActive("SAP Easy Access")


;select control field
ControlCommand("[CLASS:SAP_FRONTEND_SESSION]", "", "Edit1", "editpaste", "ZCS0")
; Press checkmark button
ControlClick("SAP Easy Access", "", "[ID:59392]", "left", 1, 19, 15)


WinWait("BOM Reports for Engr. Documents (ZCS0)", "")
If Not WinActive("BOM Reports for Engr. Documents (ZCS0)", "") Then WinActivate("BOM Reports for Engr. Documents (ZCS0)", "")
WinWaitActive("BOM Reports for Engr. Documents (ZCS0)", "")

; Select the Single Asm report
ControlClick("BOM Reports for Engr. Documents (ZCS0)", "", "[ID:100]", "left", 1, 101, 103)
Send("{ENTER}")


WinWait("BOM Report Selection - Single Assembly", "")
$hWnd = WinGetHandle("BOM Report Selection - Single Assembly") ; Get a UNIQUE handle to this window! So we can use it every time we want and don't have to be worrying about if this is still the same window.
If Not WinActive($hWnd, "") Then WinActivate($hWnd, "")
WinWaitActive($hWnd, "")

; paste part number in field
;Send("{CTRLDOWN}v{CTRLUP}{ENTER}")
;ver 2: does field have an entry
$myClip = ClipGet()
Send($myClip & "{ENTER}")
;; If you're assuming here this action closes the previous window, then you need to make sure this window is closed like so:
;; WinWaitClose($hWnd)


WinWait("BOM Report Selection - Single Assembly", "") ; <== Is this a new window?! If so, then get the handle to it on the next line like so:
;$hWnd = WinGetHandle("BOM Report Selection - Single Assembly") ; Get a UNIQUE handle to this window! So we can use it every time we want and don't have to be worrying about if this is still the same window.
; If this is not a new window then make it use the $hWnd variable from the previous window!!
If Not WinActive("BOM Report Selection - Single Assembly", "") Then WinActivate("BOM Report Selection - Single Assembly", "")
WinWaitActive("BOM Report Selection - Single Assembly", "")


ControlClick("BOM Report Selection - Single Assembly", "", "[ID:100]", "left", 1, 24, 353)
Send("{tab}{end}")
;ControlClick("BOM Report Selection - Single Assembly", "", "[ID:400]", "left", 1, 360, 353)
Send($myClip & "{ENTER}")

; Close Information window
WinWait("[TITLE:Information; CLASS:#32770]", "")
$hWnd = WinGetHandle("[TITLE:Information; CLASS:#32770]")
ControlGetFocus("[TITLE:Information; CLASS:#32770]")
ControlSend("[TITLE:Information; CLASS:#32770]", "", "", "{ENTER}")

If Not WinActive("SAP Easy Access") Then WinActivate("[CLASS:SAP_FRONTEND_SESSION]")
Do
    Send("{f3}")
Until WinActive("SAP Easy Access")

WinWait("[REGEXPTITLE:^.* - Microsoft Word$]", "")
If Not WinActive("[REGEXPTITLE:^.* - Microsoft Word$]", "") Then WinActivate("[REGEXPTITLE:^.* - Microsoft Word$]", "")
WinWaitActive("[REGEXPTITLE:^.* - Microsoft Word$]", "")

Func Quit()
    Exit 0
EndFunc   ;==>Quit

Edit: Forgot to mention. If you have more problems with the code or have any questions at all, don't hesitate to ask me again. :P

Edited by Manadar

Share this post


Link to post
Share on other sites

Hi TS,

I'm working on some SAP scripts as well and found a gem that helps in my scripts.

Now I'm fairly new to Autoit but i found that everytime SAP is "thinking" Eg: if you change subwindows within SAP of if you add info and press [enter] the ExStyle of the window changes.

So I use this code for my waits when SAP is processing:

$hWnd = WinGetHandle("ADD SAP WINDOW NAME HERE")
$style = _WinAPI_GetWindowLong($hWnd, $GWL_EXSTYLE)
while $style = 272;VALUE OF ExStyle WHEN SAP IS PROCESSING
    $style = _WinAPI_GetWindowLong($hWnd, $GWL_EXSTYLE)
WEnd
while $style = 256;VALUE OF ExStyle WHEN SAP IS IDLE
    $style = _WinAPI_GetWindowLong($hWnd, $GWL_EXSTYLE)
WEnd

hope this helps if not well sorry for the spam

Negative1


What are we going to do tonight Brain?Same thing we do every night Pinky try to automate the world.

Share this post


Link to post
Share on other sites

I have added to the code. I will let you know how it works after I have had some data to put thru SAP.

Thanks to both of you!!

Trip

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  
Followers 0