Jump to content

.NET write script using static labels rather than the control ids of the fields


Rishav
 Share

Recommended Posts

Hi folks

I have a .net application like this;

Posted Image

a simple login window.

the windows info for the label "Username" is

>>>> Window <<<<
Title:  ABC Login
Class:  WindowsForms10.window.8.app.0.378734a
Position:   492, 381
Size:   296, 189
Style:  0x16C80000
ExStyle:    0x00050101
Handle: 0x000A1006

>>>> Control <<<<
Class:  WindowsForms10.STATIC.app.0.378734a
Instance:   3
ClassnameNN:    WindowsForms10.STATIC.app.0.378734a3
Advanced (Class):   [CLASS:WindowsForms10.STATIC.app.0.378734a; INSTANCE:3]
ID: 790652
Text:   Data Source
Position:   16, 32
Size:   72, 16
ControlClick Coords:    46, 11
Style:  0x5600000D
ExStyle:    0x00000000
Handle: 0x000C107C

and the info for the text box for username is;

>>>> Window <<<<
Title:  ABC Login
Class:  WindowsForms10.window.8.app.0.378734a
Position:   492, 381
Size:   296, 189
Style:  0x16C80000
ExStyle:    0x00050101
Handle: 0x000A1006

>>>> Control <<<<
Class:  WindowsForms10.EDIT.app.0.378734a
Instance:   1
ClassnameNN:    WindowsForms10.EDIT.app.0.378734a1
Advanced (Class):   [CLASS:WindowsForms10.EDIT.app.0.378734a; INSTANCE:1]
ID: 2560220
Text:   
Position:   96, 32
Size:   176, 20
ControlClick Coords:    62, 11
Style:  0x560100C0
ExStyle:    0x00000200
Handle: 0x002710DC

At present when i need to script auto login, i write a script like

ControlSend("ABC Login","","[CLASS:WindowsForms10.EDIT.app.0.378734a; INSTANCE:1]","rishav")

But this feels extremely unelegant and i am hardcoding the script to the class/instance instead of the label name. In essence i would like to write the whole script using the fields' labels rather than the class/instance.

will it be possible for me to write a script like

$var=GetControl("ABC Login","Username")
CustomSend("ABC Login","$var,"rishav")

or

CustomCommand("ABC Login","Username","rishav")

Anyone has any ideas or advices?

Edited by Rishav
Link to comment
Share on other sites

Try this. It won't reference the the edit controls by their static label, but you can identify the controls by their design-time name (i.e., txtUsername, txtPassword ).

Link to comment
Share on other sites

Thanks for replying zfisher. I read that page before and while informative it didn't help this specific predicament of mine.

when we used to work in watir for java apps, the mapping between the static and edit controls was quite easy.

I need something similar here. Calling the Edit control using the static control text. :/

Link to comment
Share on other sites

Thanks for replying zfisher. I read that page before and while informative it didn't help this specific predicament of mine.

when we used to work in watir for java apps, the mapping between the static and edit controls was quite easy.

I need something similar here. Calling the Edit control using the static control text. :/

Understood. You will not find the functionality you speak of natively in AutoIt. I have seen that MS Active Accessibility provides that functionality ( for controls that implement IAccessible ), but we're back to the problem of what is available natively, and MSAA does not appear to be utilized in AutoIt.

The only thing I could suggest further is to create a GUI map that you can reference in code. That may be more trouble than it is worth as you would have to modify this map whenever the GUI changes. How you persist your map is a matter of choice, but I've used an Excel spreadsheet as a low-cost data store for the mappings.

You mention that you've used WATIR with Java apps. From my limited experience in Java land, I have seen that Java renders its controls in a proprietary manner, i.e., they are not exposed as windows that respond to AutoIt's method of control discovery and manipulation. I also noticed you mentioned "We" which makes me wonder if you're working in a dev shop of some kind. If you are, is it possible to ask to the dev team to name their controls in a manner that present its purpose, and thus would allow you to utilize WM_GETCONTROLNAME?

I guess what I really need want to know is: What are trying to ultimately accomplish with AutoIt? Are you wanting a GUI driver for Automated Tests?

Sorry I could not be any more help.

Zach...

Edited by zfisherdrums
Link to comment
Share on other sites

  • 3 weeks later...

hi Zfisher.

my company was trying to get an open source GUI automation tool up and i was spiking to see if Autoit will be able to handle it.

It doesn't looks like it will b easy to bring in the mappaing without some heavy work. But thanks for your time and help all the same.

regards

Rishav.

Link to comment
Share on other sites

  • Moderators

hi Zfisher.

my company was trying to get an open source GUI automation tool up and i was spiking to see if Autoit will be able to handle it.

It doesn't looks like it will b easy to bring in the mappaing without some heavy work. But thanks for your time and help all the same.

regards

Rishav.

_CtrlGetByPos() http://www.autoitscript.com/forum/index.ph...c=30717&hl=

_WinGetCtrlInfo() http://www.autoitscript.com/forum/index.ph...c=32781&hl=

Edit:

After "re-reading" it, I am totally off base :) ...

Zfisher does have an interesting approach. And it really is very little effort.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

thanks smoke.

i am checking if the dev team can put in a control id/label mapping but it doesn't seems likely.

anyway, thanks for your help.

regards.

I'm not going to pretend to know .NET, but am I to understand that you create an edit control, that it automatically creates a static control label for you?

Otherwise, I'd have no idea how you would accomplish this with any language without mapping it.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

from what i know, a static control is created but the textfield and the text label both get different and separate static controls. you can't use the static control for the textfield if you know static control for the text label, and vise versa.

the biggest problem is that the software was originally developed by another party and they never gave a thought for automation and such.

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...