Jump to content

Reg: Regular Expression handling in AutoIT


Recommended Posts

Hi, We are trying to automate the SAP applications. For automating that we are using sap.au3 wrapper file. Facing some issues with the dynamic control values

example: Please consider the highlighted values.

("usr/subSUB0:SAPLMEGUI:0015/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB2:SAPLMEGUI:1303/tabsITEM_DETAIL/tabpTABIDT3")

("usr/subSUB0:SAPLMEGUI:0019/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB2:SAPLMEGUI:1303/tabsITEM_DETAIL/tabpTABIDT13")

While in execution we are getting either 15 or 19 and some times 13 also. How to handle this in autoit. What i though was through autoit regular expression we can ? but didn't get the proper guidelines and time to implement. If you have any idea how to handle this issue, please let me know.

Thanks

Manivel P

Link to comment
Share on other sites

You want to extract the value ?

Local $sString = '("usr/subSUB0:SAPLMEGUI:0015/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB2:SAPLMEGUI:1303/tabsITEM_DETAIL/tabpTABIDT3")'
Local $aval = StringRegExp($sString, "SAPLMEGUI:00(\d+)", 1)
MsgBox(0, "", $aval[0])

 

Link to comment
Share on other sites

Actually its SAP Control property value. property values changed based on the selections. That value is belong to one of the menu option.

for example - in outlook we have home, Send/Receive, Folder, View extra right. Same thing.

if the particular menu selected by default - then the property id is usr/subSUB0:SAPLMEGUI:0015............................

if some other tab is selected or expanded, then we need to select the expected menu means  - the property id is usr/subSUB0:SAPLMEGUI:0019...

Not sure about the default selection. Its based on the users. so we need to handle this id's in regular expression.

Thank you

Edited by Manivel
Link to comment
Share on other sites

you don't need regular expressions provided the data is always in the same model

$sString = '("usr/subSUB0:SAPLMEGUI:0015/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB2:SAPLMEGUI:1303/tabsITEM_DETAIL/tabpTABIDT3")'
msgbox(0, '' , number(stringsplit(stringsplit($sString , "/" ,2)[1] , ":" , 2)[2]))

 

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

nice, I like bringing you to the darkside

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

9 hours ago, iamtheky said:

you don't need regular expressions provided the data is always in the same model

$sString = '("usr/subSUB0:SAPLMEGUI:0015/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB2:SAPLMEGUI:1303/tabsITEM_DETAIL/tabpTABIDT3")'
msgbox(0, '' , number(stringsplit(stringsplit($sString , "/" ,2)[1] , ":" , 2)[2]))

 

my concern is the values what you are showing in msg box is dynamic value. it may be 15 or 13 or 19  or any value. Its a control [button]. I need to click that button. The property value might be 15 or any value. Through sub string we can get the value. How to replace that value. Because the expected value is dynamic. thats why i thought of asking about regular expression.

Link to comment
Share on other sites

It totally doesn't matter what the value is, all the solutions provided would facilitate identifying the target. 

And replacing it is trivial with any of the solutions, but hopefully this is the part where everyone encourages you to try and work through the provided answers and post code when you have issues, rather than us just handing you functional code.

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

  • 1 year later...

Hello.

     Was there a solution for this? I'm having the exact same problem and I can't find anything to identify which ID it's the correct one at the moment. Autoit it's crashing if the ID doesn't exist and can't continue with the rest of the script.

 

Link to comment
Share on other sites

  • Developers

Show us an example of the script that demonstrates your issue please, else it's hard to know what is going wrong.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Sure,

     This is one of my issues, I need to select "Delivery/Invoice" everytime I access to SAP:

     5b60d3bc87baf_SAPTabSelector.thumb.png.e55991083c117a8f2c64553225602c93.png

     One ID for Delivery/Invoice is: "wnd[0]/usr/subSUB0:SAPLMEGUI:0018/subSUB1:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1102/tabsHEADER_DETAIL/tabpTABHDT1",  however can change to 10 or 13 as well, but I have no way to identify which one is active everytime I log in. I can use keystrokes but that will be my very last option.

     I did try several options, not only IsObj with no luck. I did read so many threads from here as well but nothing that can help me as well. If AutoIt can only keep going instead of crashing if the ID is not there, that will be awesome since it will just continue unitl it finds the one that exists.

     The code I'm using so far is:

Local $oSapGuiAuto, $Application, $Connection, $Session
Local $Info

$oSapGuiAuto = ObjGet("SAPGUI")
If Not IsObj($oSapGuiAuto) Or @error Then
    Exit
EndIf

$Application = $oSapGuiAuto.GetScriptingEngine()
If Not IsObj($Application) Then
    Exit
EndIf

$Connection = $Application.Children(0)
If Not IsObj($Connection) Then
    Exit
EndIf

$Session = $Connection.Children(0)
If Not IsObj($Session) Then
    Exit
EndIf

; Accessing ME23N Transaction

$Session.findById("wnd[0]/tbar[0]/okcd").text = "me23n"
$Session.findById("wnd[0]").sendVKey(0)

Opt("WinTitleMatchMode", 2)
WinWaitActive("Standard PO", "")

; Selecting the proper tab

$SAPSupplier10 = "wnd[0]/usr/subSUB0:SAPLMEGUI:0010/subSUB1:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1102/tabsHEADER_DETAIL/tabpTABHDT1"
$SAPSupplier13 = "wnd[0]/usr/subSUB0:SAPLMEGUI:0013/subSUB1:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1102/tabsHEADER_DETAIL/tabpTABHDT1"
$SAPSupplier18 = "wnd[0]/usr/subSUB0:SAPLMEGUI:0018/subSUB1:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1102/tabsHEADER_DETAIL/tabpTABHDT1"

If IsObj($SAPSupplier10) Then
    $Session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0010/subSUB1:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1102/tabsHEADER_DETAIL/tabpTABHDT1").select
EndIf

If IsObj($SAPSupplier13) Then
    $Session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0013/subSUB1:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1102/tabsHEADER_DETAIL/tabpTABHDT1").select
EndIf

If IsObj($SAPSupplier18) Then
    $Session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0018/subSUB1:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1102/tabsHEADER_DETAIL/tabpTABHDT1").select
EndIf

 

This is the error I'm getting if the ID does not exist:

"C:\Autoit\Test.au3" (73) : ==> The requested action with this object has failed.:
$Session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0017/subSUB1:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1102/tabsHEADER_DETAIL/tabpTABHDT1").select
$Session^ ERROR
->14:49:02 AutoIt3.exe ended.rc:1
+>14:49:02 AutoIt3Wrapper Finished.

Thanks!!

 

 

Link to comment
Share on other sites

in vba

Sub test10()

If Not IsObject(App) Then
   Set SapGuiAuto = GetObject("SAPGUI")
   Set App = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(Connection) Then
   Set Connection = App.Children(0)
End If
If Not IsObject(session) Then
   Set session = Connection.Children(0)
End If
If IsObject(WScript) Then
   WScript.ConnectObject session, "on"
   WScript.ConnectObject Application, "on"
End If
session.findById("wnd[0]").resizeWorkingPane 102, 31, False
 Set Dummy01 = session.findById("wnd[0]/usr/").Children
 Dummy02 = Dummy01.Item(1).ID
 
End Sub

Link to comment
Share on other sites

      Thanks for the reply!!, I'm not really that pro to understand the last part of the code without some additional information however I did find another way to "identify" which ID is the correct and continue, basically I did create 1 VBS script file per ID and I did run them with RunWait like this:

RunWait('cscript.exe "' & @ScriptDir & '\Scripts\DeliveryInvoiceTab 10.vbs"', "", @SW_HIDE)
RunWait('cscript.exe "' & @ScriptDir & '\Scripts\DeliveryInvoiceTab 13.vbs"', "", @SW_HIDE)
RunWait('cscript.exe "' & @ScriptDir & '\Scripts\DeliveryInvoiceTab 18.vbs"', "", @SW_HIDE)

      This works like a charm if I just need to select something however I'm not able to extract data from a SAP field to an AutoIt Variable through VBS. Should I need to open a new thread regarding this issue? 

Thanks again. :)

Link to comment
Share on other sites

Sorry was in a hurry

Dummy02  =  "/app/con[0]/ses[0]/wnd[0]/usr/subSUB0:SAPLMEGUI:0015"

Should be easy to convert to Autoit, if not will work on it Monday

(if you have excel paste in into a VB modal and step thru (f8) viewing the Locals Window)

Let me know if you don't understand and I will elucidate on Monday.

I think you will only add 1 line.

How many sessions do you have open at a time?

Do you want the fish or to know how to get it?

 

Edited by jitb
Make it a little clearer, I hope :-)
Link to comment
Share on other sites

  • 2 weeks 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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...