Jump to content
Sign in to follow this  
Andrew

Ever changing ControlID

Recommended Posts

Andrew

I am struggling with how to adjust my script for a periodically changing ControlID. Once instance of the app window I'm getting info from may have

"[CLASS:WindowsForms10.COMBOBOX.app.0.3a9f0c; INSTANCE:1]"

But a later instance may have:

"[CLASS:WindowsForms10.COMBOBOX.app.0.68373; INSTANCE:1]"

Is there a way to query the form to get the ControlID? I've been using the AutoIt Window Info Tool to get it but if there is a way to do it within the script then perhaps I could substitute it on the fly?

Thanks!

Share this post


Link to post
Share on other sites
Andrew

Assuming you're referring to 'ControlGetText', do you have a working example that would demonstrate how this works? I tried the example in the Help file and, frankly, I just don't get it :-(

Run("notepad.exe")
$var = ControlGetText("[CLASS:Notepad]", "", "Edit1")

Not sure what I'm looking at (I'm still a newbie)

Sorry.

Share this post


Link to post
Share on other sites
Andrew

Sorry, my bad. Only half of the form has control text; the rest are blank. If I know the control text to part of the form, can I get the control id from it?

Share this post


Link to post
Share on other sites
PsaltyDS

How about something like this:

$hWin = WinGetHandle("YourWindowTitle", "")
$hCombo = ControlGetHandle($hWin, "", "[REGEXPCLASS:WindowsForms10\.COMBOBOX\.app\.0.\; INSTANCE:1]")

See help file under "Controls" for other advanced specifications you can use.

:mellow:

Edit: Forgot closing square bracket

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
JohnOne

Heres a quick example

$gui = GUICreate("GUI");make a gui
$okbutton = GUICtrlCreateButton("OK",10,10);put a button on it wit "OK" text
GUISetState();show the gui

Do
    Sleep(2000)
    ControlClick($gui,"OK","");click the button using the text as identifier
Until GUIGetMsg() = $okbutton

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites
Andrew

How about something like this:

$hWin = WinGetHandle("YourWindowTitle", "")
$hCombo = ControlGetHandle($hWin, "", "[REGEXPCLASS:WindowsForms10\.COMBOBOX\.app\.0.\; INSTANCE:1]")

See help file under "Controls" for other advanced specifications you can use.

:mellow:

Edit: Forgot closing square bracket

So right now I have the following:

# Select 'Remote' from the Onsite/Remote pulldown menu
ControlSend("YourWindowTitle", "", "[CLASS:WindowsForms10.COMBOBOX.app.0.3a9f0c; INSTANCE:1]", "r")

I would change it to?

$hWin = WinGetHandle("YourWindowTitle", "")
$hCombo = ControlGetHandle($hWin, "", "[REGEXPCLASS:WindowsForms10\.COMBOBOX\.app\.0.\; INSTANCE:1]")
ControlSend("YourWindowTitle", "", $hCombo, "r")

Share this post


Link to post
Share on other sites
PsaltyDS

Close. Once you get the window handle you don't have to mess with the title anymore:

ControlSend($hWin, "", $hCombo, "r")

:mellow:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
Andrew

Excellent! I will try it out next week and let you know!

Thanks PsaltyDS

Share this post


Link to post
Share on other sites
Andrew

PsaltyDS,

I modified my code but it didn't work (no errors but didn't update the form fields).

$hWin = WinGetHandle("Non Deliverable Task", "")
WinWait($hWin, "")
If Not WinActive($hWin, "") Then WinActivate($hWin, "")
WinWaitActive($hWin, "")
$hTitle = ControlGetHandle($hWin, "", "[REGEXPCLASS:WindowsForms10\.EDIT\.app\.0.\; INSTANCE:5]")
$hCombo1 = ControlGetHandle($hWin, "", "[REGEXPCLASS:WindowsForms10\.COMBOBOX\.app\.0.\; INSTANCE:1]")
$hCombo4 = ControlGetHandle($hWin, "", "[REGEXPCLASS:WindowsForms10\.COMBOBOX\.app\.0.\; INSTANCE:4]")
$hCombo6 = ControlGetHandle($hWin, "", "[REGEXPCLASS:WindowsForms10\.COMBOBOX\.app\.0.\; INSTANCE:6]")
$hCombo8 = ControlGetHandle($hWin, "", "[REGEXPCLASS:WindowsForms10\.COMBOBOX\.app\.0.\; INSTANCE:8]")
$hCombo7 = ControlGetHandle($hWin, "", "[REGEXPCLASS:WindowsForms10\.COMBOBOX\.app\.0.\; INSTANCE:7]")

# Enter Subject line text
ControlSetText($hWin, "", $hBenefits, "Bulletin Notification")
# Select 'Remote' from the Onsite/Remote pulldown menu
ControlSend($hWin, "", $hCombo1, "r")
# Select 'Bulletin Check' from the Subtask pulldown menu
ControlSend($hWin, "", $hCombo4, "s")
# Select 'Complete' from the Status pulldown menu
ControlSend($hWin, "", $hCombo6, "c")
# Select 'Problem Management' from the Category pulldown menu
ControlSend($hWin, "", $hCombo8, "p")
# Select 'Improve Availability' from the CSF Primary pulldown menu
ControlSend($hWin, "", $hCombo7, "i")

Ideas?

Edited by Andrew

Share this post


Link to post
Share on other sites
PsaltyDS

Check/display the handle returned by ControlGetHandle() to see if that's what failed.

Do you know of a common app we might have that would show this approx type of control for testing?

:mellow:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
Andrew

Taking your "\" backslashes out took care of the problem.

Thanks again! :mellow:

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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.