Jump to content

Get visible control by ID (mutliple matching controls)


jdelaney
 Share

Recommended Posts

My software I'm attempting to automate includes a Button that can be present any number of times, but only one will be visible at a time.

I was hoping something like this would work

$hApplication = "MyApplication"
$giWebWorkList_ButtonAddToWorklist = 4642 ; The ID of the controls
$iLoop = 1
While True
 $hAddToWorklist = ControlGetHandle($hApplication, "", "[CLASSNN:Button" & $iLoop & "; ID:" & $giWebWorkList_ButtonAddToWorklist & "]")
 If Not IsHWnd($hAddToWorklist) Then
  ConsoleWrite ( "exit, Failure, on loop=[" & $iLoop & "]" & @CRLF )
  ExitLoop
 Else
  ConsoleWrite ( $iLoop & " " & $hAddToWorklist & @CRLF )
 EndIf
 $bFound1 = ControlCommand($hApplication, "", $hAddToWorklist, "IsVisible", "")
 $bFound2 = ControlCommand($hApplication, "", $hAddToWorklist, "IsEnabled", "")
 If $bFound1 And $bFound2 Then
  ConsoleWrite ( "Found visible instance of buttonid=[]; where IsVisible=[" & $bFound1 & "] and IsEnabled=[" & $bFound2 & "] on Instance=[" & $iLoop & "]; Handle=[" & $hAddToWorklist & "]; id being searched=[" & $hAddToWorklist & "]." & @crlf )
  ExitLoop
 EndIf
 $iLoop += 1
WEnd

But in the ControlGetHandle function, BOTH the CLASSNN and ID are not conisidered, only the CLASSNN...so the first visible,enabled, button is returned, regardless of the ID NOT being the one I'm searching for.

I also attempted using the ID, and Instance:

$hAddToWorklist = ControlGetHandle($hApplication, "", "[ID:" & $giWebWorkList_ButtonAddToWorklist & "; INSTANCE:" & $iLoop & "]")

But the instance param is not considered, it only returns the first applicable control matching the ID

Please let me know of a workaround...or, is there a way to take a handle, and return it's control's ID? If so, that would solve my problem...thanks!

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

Found a workaround...all the buttons share the same position, so I'm looping through all buttons until I find the visible one with the proper posistion...would still much rather be able to get the control ID from the handle...(if the autoit windo winfo tool can do it, why can't I :) )

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
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
 Share

  • Recently Browsing   0 members

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