Peak
Peak

Reputation: 21

SAP GUI scripting - Button press fails

I am using a macro in an Excel file that runs the SAP GUI. There is a step where, when I click a button in SAP there will be another window that pops up.

For that I have written a code like this:

session.findbyid("wnd[0]/XX/btnXX").press
session.findbyid("wnd[1]/XX/btnXXX").press

There is a button (btnXXX) in the window (wnd[1]). But when I execute this query, I am getting an error object not found for findbyid.

When I keep the break point and execute it, it is throwing error on 2nd line in the above code. I try to pick the activewindow.name and it shows wnd[0] still. Here the issue is wnd[1] is not getting opened.

Does somebody know why the 2nd "button press" doesn't work?

Upvotes: 2

Views: 7537

Answers (1)

Adam Milecki
Adam Milecki

Reputation: 1796

You should be able to replace all mouse clicks with keyboard strokes.

Replace:

session.findbyid("wnd[0]/XX/btnXX").press

With:

session.findById("wnd[0]").sendVKey(N)

Where N is the linked hot-key ID.

To get the exact command, use SAP script recording and only use the keyboard to transition between views and windows. The easiest way to determine how is to hover your mouse over the buttons you would normally click to learn the hot-key then record the hot-key.

Note 1) So far I have found that btn[XX] always maps to sendVKey(XX), but I can't be certain this is always the case.

Note 2) sendVKey always appears to be referenced off the window (wnd[Y]) even if a button is another layer down (/tbar, /usr, etc.).

Upvotes: 2

Related Questions