maniootek Posted April 25, 2019 Share Posted April 25, 2019 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) Link to comment Share on other sites More sharing options...
Danp2 Posted April 25, 2019 Share Posted April 25, 2019 Have you tried using just the information under Advanced (Class), ie: [CLASS:AfxWnd80u; INSTANCE:16] ? Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
YellowAfterlife Posted April 26, 2019 Share Posted April 26, 2019 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. Link to comment Share on other sites More sharing options...
jdelaney Posted April 26, 2019 Share Posted April 26, 2019 (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 April 26, 2019 by jdelaney argumentum 1 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 More sharing options...
argumentum Posted April 26, 2019 Share Posted April 26, 2019 I don't have the "know how" but maybe you can use SendMessage() to talk to ithttps://docs.microsoft.com/en-us/cpp/mfc/reference/afx-messages?view=vs-2019https://docs.microsoft.com/en-us/windows/desktop/controls/button-messages#sending-messages-to-buttonshttps://www.codeguru.com/cpp/misc/misc/article.php/c301/HOWTO-MFC-user-defined-message-maps.htmhttps://www.google.com/search?q=sendmessage+AFX+contorls&nfpr=1 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
maniootek Posted April 27, 2019 Author Share Posted April 27, 2019 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" Link to comment Share on other sites More sharing options...
junkew Posted April 29, 2019 Share Posted April 29, 2019 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]") FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
maniootek Posted April 29, 2019 Author Share Posted April 29, 2019 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) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now