Selecting the Xth item in a dropdown menu using the arrow keys in UFT

77 Views Asked by At

I'm passing an argument X to a subroutine in UFT that will go to a dropdown control and select the Xth item

My first attempt worked, and I was basically just sending 'up' a bunch of times to get ensure I was at the top of the menu, then 'down' X times to get to the item I wanted

Win().Click 431, 548 'selecting the dropdown
        
For Iterator = 1 To 10 Step 1 'reset the selector to be on the top level
    Win().Key micUp
Next
For Iterator = 1 To X Step 1
    Win().Key micDwn
Next
Win().Key micReturn


However, the input happened very slowly, and I wanted it to happen faster, so I tried to concatenate all of the buttons I wanted to press before calling the Key function a single time:

Win().Click 431, 548 'selecting the dropdown
        
Dim KeyInput
KeyInput = ""
For Iterator = 1 To 10 Step 1 'reset the selector to be on the top level
    KeyInput = KeyInput & micUp
Next
For Iterator = 1 To X Step 1
    KeyInput = KeyInput & micDwn
Next
KeyInput = KeyInput & micReturn

Win().Key KeyInput

However, I'm not getting any key inputs at all with this - is there a different way to concatenate?

EDIT: as for other methods, it's not a standard dropdown, so I can't do anything that relies on interacting with it directly as far as I can tell.

1

There are 1 best solutions below

4
Motti On

When you say very slowly, how slowly do you mean? I see two options:

  • The object you're identifying uses smart-identification which makes it very slow (as described in this question). In which case you can either try to solve the issue as described there, or a workaround is to capture the object in a variable with Set which will prevent it being identified every time it's being used (if it's safe to do so, further reading).
  • The steps are only a bit slow, in which case check the interval between steps in the Run Mode part of the settings Screenshot of options