Jump to content
maniootek

Find control with ID and other property

Recommended Posts

I have app which has two controls with same ID

Control 1:

Quote

Class:    AfxWnd80u
Instance:    16
ClassnameNN:    AfxWnd80u16
Name:    
Advanced (Class):    [CLASS:AfxWnd80u; INSTANCE:16]
ID:    106
Text:    WYŚLIJ/ODBIERZ


Control 2:

Quote

Class:    ins_combohyperlink
Instance:    24
ClassnameNN:    ins_combohyperlink24
Name:    
Advanced (Class):    [CLASS:ins_combohyperlink; INSTANCE:24]
ID:    106
Text:    

I want to use ControlClick() function on control 1.

When I use this code:

ControlClick($hApp, "", "[ID:106; TEXT:WYŚLIJ/ODBIERZ; CLASS:AfxWnd80u]")

then my script click on the control 1 but another time on control 2 (I think it depends which control is first in the objects tree). It seems that ID parameter is the only property which script try to match. Text or class are ignored.

How can I force ControlClick to match all properties?
(I also changed text or class with non-exists values and it still match control with id 106)
 

Share this post


Link to post
Share on other sites

If the two controls aren't also within the same container, you can try doing ControlGetHandle on the container, and then passing the handle to ControlClick as the first argument.

Share this post


Link to post
Share on other sites
Posted (edited)

I have some udf that can do that. I'll upload them tonight. It allows you to find controls with any combination of data points including text, id, class, visibility enabled status, etc.

 

Note: it does not include logic on instance. Personal preference to never use that property because instances change with business logic in most apps

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.

Share this post


Link to post
Share on other sites
On 4/25/2019 at 11:01 PM, Danp2 said:

Have you tried using just the information under Advanced (Class), ie:  [CLASS:AfxWnd80u; INSTANCE:16] ?

Yes of course and this is the solution but this is not the answer I am looking for.

I am just curious why functions such ControlClick where you can use special format like

Quote

[ID:106; TEXT:WYŚLIJ/ODBIERZ; CLASS:AfxWnd80u]

does not try to match all properties but only ID. In case there is control with ID 106 but TEXT is not as specified, it should return @error not null, am I right? Maybe this is bug or help file is not clear enough under thread "Controls"

Share this post


Link to post
Share on other sites

You can do this with UIA. See examples sections. 

 

Maybe order makes a difference

ControlClick($hApp, "", "[CLASS:AfxWnd80u; TEXT:WYŚLIJ/ODBIERZ; ID:106]")

Based on the help I would say your example should be working but probably hard to make a reproducing script so others can replay

ControlClick("My Window", "", "[CLASS:Button; TEXT:Finish; INSTANCE:2]")

 

Share this post


Link to post
Share on other sites
5 minutes ago, junkew said:

You can do this with UIA. See examples sections. 

My script was writted using UIA before with Click function then I relized that ControlClick suppose to do the same job with less code and ControlClick is better than Click because it might click on the control without focus (control might be covered with other window and controlclick function still can click on it). By the way, is there a method to controlclick with UIA? (I don't mean Invoke method)

 

11 minutes ago, junkew said:

Maybe order makes a difference

ControlClick($hApp, "", "[CLASS:AfxWnd80u; TEXT:WYŚLIJ/ODBIERZ; ID:106]")

 

I already tired change the order but this makes no difference

 

14 minutes ago, junkew said:

hard to make a reproducing script so others can replay

yes, it's hard to find app which has more than one control with the same ID.

I think this shoud be checked with more advanced AutoIt user (who has access to the code of controlclick function)

Share this post


Link to post
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

×
×
  • Create New...