Determine control name

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
jellyfish5000
Newbie
Posts: 3
Joined: Fri Feb 02, 2007 10:58 am
Location: Wigan, England

Determine control name

Post by jellyfish5000 » Fri Feb 02, 2007 11:49 am

Hi - newbie here!
I'm currently using a trial version of the software to determine whether to proceed with it.
We provide Genero/Informix based database software which is very customer bespoke. We have many clients who use many "generic" features of our software, but we have quite a few customers who have a basic generic system which is tailored to meet their own specific requirements.
Therefore, what we have are some clients who have certain textboxes on their forms, whereas other clients do not have these textboxes at all - indeed, they might even have textboxes that are exclusive to themselves. As you can imagine, this makes the automation of testing a nightmare.
What I want to do is write script which can determine the 'name' of the textbox control, and act accordingly - so, for example, by pressing tab to move to the next field, it can use the 'name' and run a section of script applicable to the 'name' of the text box.
Is it possible to return the name of the control and work with it?

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Fri Feb 02, 2007 12:06 pm

As far as I am aware this isn't possible. Objects publish their class names and handles, but they don't have a name beyond how they are identified in the source code of the application. At run time, that name would be no use to an external process.

You can get the handle, class name and caption text but there's really no such thing as a "name" as far as Windows is concerned at the presentation layer. The handle changes each time, and if you have several items with the same class name, and the amount varies each time, this doesn't help either.

If it is possible to initialise the form so that each field had a unique value, you could then identify each control based on those initial values using FindWindow/FindWindowEx. Once identified, and the handles obtained, the initial values can be changed.

You can get the caption text of labels. So if each field has a label and you can predetermine where the edit box appears in relation to the label, and you are able to retrieve the X,Y position of the label ... then you could be on to something. But even if possible, this is going to be hideously difficult, especially if you are not used to scripting and using the Windows API.

An easier solution might be a graphical approach using the image recognition functions. If you capture images of each of the labels and build in offsets for the associated edit boxes you can a) determine if the label exists on the window, and b) identify the position of the associated edit box. Use the image recognition functions to "see" what's on the screen and retrieve object positions:

http://www.mjtnet.com/imagerecognition.htm
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

jellyfish5000
Newbie
Posts: 3
Joined: Fri Feb 02, 2007 10:58 am
Location: Wigan, England

Post by jellyfish5000 » Fri Feb 02, 2007 1:25 pm

Thanks for your reply.
Unfortunately, we won't be able to, for example, use the determined position of labels because the position of the label for one client may not be the same as the next.
By the sound of it, what we need is probably outside the scope of the software at this stage.

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Fri Feb 02, 2007 4:40 pm

Hi,

I wasn't suggesting that you DO rely on the position of labels. What I was saying was that based on the label CAPTION you can FIND the label and RETURN it's position and therefore determine the EDIT field position. This could be done using image recognition, or possibly, with more complicated Windows API.

I am not saying that your script uses absolute positions, but rather it FINDs the positions to find the edits. Perhaps my last post was not clear.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

jellyfish5000
Newbie
Posts: 3
Joined: Fri Feb 02, 2007 10:58 am
Location: Wigan, England

Post by jellyfish5000 » Fri Feb 02, 2007 4:43 pm

oh, I see. Thanks.
I'll have to investigate this possibility.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts