Jump to content

Recommended Posts

Posted

Hi,

Are there any tricks I can use to identify a control (for use with the ControlXXX commands) when the

CLASS and ID seem to be changing each time the application is run.

It's a .NET app and I think the form is dynamically adding the controls...

I was using an id like this:

"[CLASS:WindowsForms10.BUTTON.app4; INSTANCE:1]"

but when I run the program as different users, the app4 part changes (I've seen app4 and app5).

I changed to using ID (eg "[iD:65432]") but the ID of the button changes every time the application runs (although I read in the forum or faq that the ID is supposedly the most reliable way of identifying a control).

The button I want to activate has an image but no text, however fortunately it's our own application so I've worked around it by adding a tiny button (hidden behind the original one) which performs the same action and has text which I can use (So now I'm using "[TEXT:Blah]") to find the hidden button and I'm sending a message to that instead.

Still I was wondering if anyone knows if there is a better way of doing it or of getting the .NET forms to generate a consistent id that is visible to AutoIt (I tried setting AccessibleName and properties like that but couldnt find them in the autoit info).

cheers

Posted

I've tried automating a .NET application but its control ID, classname or instance never changed. So I had to go with what you said in the first post, and hope I am doing it correctly.

You can use a REGEXPCLASS to find the correct control you are looking for. It's useful to find a control by classname using a regular expression.

$hWnd = WinGetHandle("[active]")
$ControlClass = "[REGEXPCLASS:WindowsForms10\.BUTTON(.*)?; INSTANCE:1]"
$ChWnd = ControlGetHandle($hWnd, "", $ControlClass)

For more information, please look at:

http://www.autoitscript.com/autoit3/docs/f...tringRegExp.htm

http://www.autoitscript.com/autoit3/pcrepattern.html

http://www.autoitscript.com/autoit3/docs/t...gexp/regexp.htm

http://www.codeproject.com/KB/dotnet/regextutorial.aspx

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