Forum Discussion

Dewayne_Pinion's avatar
Dewayne_Pinion
Contributor
10 years ago
Solved

Clicking a button after finding WndCaption

Greetings,

I am trying to write a routine to click any button within my AUT by calling the routine and passing it the button's WndCaption property. However, I am running into an issue, that the buttons use the & to set up shortcut keys. 

 

So I am trying to do something like this:

 

Call ClickMyButton("Test")


Sub ClickMyButton(sCaption)

dim p, btn

set p = process

set btn = p.findChild("WndCaption", sCaption)

if btn.exists then
  btn.ClickButton
End if

End Sub

 

The part I am having trouble with is that the WndCaption might actually be something like Te&st, so the subroutine fails.  Any suggestions about how to handle this?

 

Thanks!

 

  • You can wildcard Test as ?T?e?s?t to account for possible hot-key ampersands in the string. Just be aware this may produce false positives.

     

    sCaption = AddWildcards("Test")
    Call ClickMyButton(sCaption)
    ...

    ' Adds ? before each character in a string, for example: ' Test -> ?T?e?s?t Function AddWildcards(Str) Dim re : Set re = New RegExp re.Pattern = "." re.Global = True AddWildcards = re.Replace(Str, "?$&") End Function

     

2 Replies

  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    You can wildcard Test as ?T?e?s?t to account for possible hot-key ampersands in the string. Just be aware this may produce false positives.

     

    sCaption = AddWildcards("Test")
    Call ClickMyButton(sCaption)
    ...

    ' Adds ? before each character in a string, for example: ' Test -> ?T?e?s?t Function AddWildcards(Str) Dim re : Set re = New RegExp re.Pattern = "." re.Global = True AddWildcards = re.Replace(Str, "?$&") End Function