Jump to content
Iulia_Vascan

How to automate button click in a GUI?

Recommended Posts

Hello,

I am new to AutoIT, I am trying to automate the push of  two buttons in a GUI.  The first one is presented in a1.png ("Add" -  Button), the second one in a2.png ("GetDP circuit" - Button).

This is my code:

Run("E:\Iulia_Vascan\dolomites-release-python\Dolomites.exe")
ControlClick("Dolomites","", controlID [, button = "left" [, clicks = 1 [, 217 [, 298]]]] )
ControlClick("Dolomites","", controlID [, button = "left" [, clicks = 1 [, 307 [, 59]]]] )
ControlFocus("Save GetDP circuit", "", "Edit1")
ControlSetText("Save GetDP circuit", "", "Edit1", "E:\Iulia_Vascan\Metoda_2\winding.pro")
ControlClick("Save GetDP circuit", "","Button2")

I write the ControlClick function as is presented in the Help - Function Reference, but it didn't work and I can't figure out why.

 

Thank you!

 

a1.png

a2.png

Share this post


Link to post
Share on other sites

Hi @Iulia_Vascan, and welcome to the AutoIt Forums :)
First of all, when you call your Control* functions, you don't have to write the square brackets, because the only mean that they are optional parameters.
Then, you have to see the Control tab in the AutoItWindowsInfoTool instead of Mouse tab; from there, you can see the Control class, ID, and so on, which you can use in your Control* functions.
So, run once again the AutoItWindowInfoTool and look at the Control button, in which there are all the information needed to use ControlClick() function :)
Once you have finished, post again your code, replacing all the information you got ;)


Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites

Since your case may be this, use Mose postion to use ControlClick():

ControlClick("Dolomites","", "", "left", 1, 215, 298)

Try this and let us know :)

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites
Run("E:\Iulia_Vascan\dolomites-release-python\Dolomites.exe")
ControlClick("Dolomites","", "", "left", 1, 215, 298)
ControlClick("Dolomites","", "", "left", 1, 307, 59)
ControlFocus("Save GetDP circuit", "", "Edit1")
ControlSetText("Save GetDP circuit", "", "Edit1", "E:\Iulia_Vascan\Metoda_2\winding.pro")
ControlClick("Save GetDP circuit", "","Button2")

@FrancescoDiMuro I tried this way, but it's not working ... the script just run the exe file and that's all. 

Share this post


Link to post
Share on other sites

so, can you give us the information for each button or object you wish to click or interact with from the Windows Information Tool? What I mean for waiting for controls is that they don't just exist immediately when the script is run, you need to wait for them.... see my WaitForControls udf, also, if they are not standard windows components, then your methods of manipulation will vary

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites

@Iulia_Vascan
What Eartshine was meaning, is that you have to wait the Controls to be "ready", in order to interact with them.
So, you could add a WinWaitActive() with your window, in order to know when your window will be active and "ready" to play with :)

 


Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites

that wraps most controls that can be clicked. to get logging working, get the logger from this site and configure it in the main script so then when you call this the logging works.


My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
1 hour ago, Earthshine said:

so, can you give us the information for each button or object you wish to click or interact with from the Windows Information Tool? What I mean for waiting for controls is that they don't just exist immediately when the script is run, you need to wait for them.... see my WaitForControls udf, also, if they are not standard windows components, then your methods of manipulation will vary

Not sure... But i think you are maybe false. How can you be sure he have to wait for a Control ? Exept if you know the software but you did not mentioned it. 

He is trying to get information from a control ... I mean if the control is visible he is existing... Or I am false  ?

 

.net application should not be able to receive a postmessage controlclick

Exept with IUIAutomation...? But still it is not post message click.


My video tutorials : HERE ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites

i know because that's how windows works. it takes time for an app that has just launched to be ready. the other theory is that they are not windows controls and he won't be able to click them using autoit anyway.


My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites

He will, if he use the IUIA UDF

So no it s not the only one Theory

 

There is some case where you cannot click and you can couturn it. 

 

Java application

.net Application

probably more 

And yes it is true that you have to wait each time you run an application:  in some milisecond.

But if you script correctly you wont access an unexistant control... You implement a sleep a winactivate or what ever....

 

I dont want to make you help small. Just advising no worry.

 

Edited by caramen

My video tutorials : HERE ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites

only option it to try IUIAutomation. let me try it. it is not made with windows controls.

IUIAutomation works, this clicks the Wizard button, then clicks it. Works! I used the portable Dolomites, and it correctly highlights everything it's looking for, in pretty good time too. do I win a badge? lol

;~ *** Standard code maintainable ***
#include "UIAWrappers.au3"
AutoItSetOption("MustDeclareVars", 1)

_UIA_setVar("oP1","Title:=Dolomites;controltype:=UIA_WindowControlTypeId;class:=Qt5QWindowIcon")    ;Dolomites
_UIA_setVar("oP2","Title:=;controltype:=UIA_CustomControlTypeId;class:=")   ;
_UIA_setVar("oP3","Title:=;controltype:=UIA_SplitButtonControlTypeId;class:=")  ;
_UIA_setVar("oP4","Title:=;controltype:=UIA_CustomControlTypeId;class:=")   ;
_UIA_setVar("oP5","Title:=;controltype:=UIA_CustomControlTypeId;class:=")   ;
_UIA_setVar("oP6","Title:=;controltype:=UIA_SplitButtonControlTypeId;class:=")  ;
_UIA_setVar("oP7","Title:=;controltype:=UIA_SplitButtonControlTypeId;class:=")  ;
_UIA_setVar("oP8","Title:=;controltype:=UIA_CustomControlTypeId;class:=")   ;

;~ $oUIElement=_UIA_getObjectByFindAll("Wizard....mainwindow", "title:=Wizard...;ControlType:=UIA_ButtonControlTypeId", $treescope_subtree)
_UIA_setVar("oUIElement","Title:=Wizard...;controltype:=UIA_ButtonControlTypeId;class:=") ;ControlType:=UIA_ButtonControlTypeId;classname:=")

;~ Actions split away from logical/technical definition above can come from configfiles

;~_UIA_Action("oP1","highlight")
_UIA_Action("oP1","setfocus")
;~_UIA_Action("oP2","highlight")
_UIA_Action("oP2","setfocus")
;~_UIA_Action("oP3","highlight")
_UIA_Action("oP3","setfocus")
;~_UIA_Action("oP4","highlight")
_UIA_Action("oP4","setfocus")
;~_UIA_Action("oP5","highlight")
_UIA_Action("oP5","setfocus")
;~_UIA_Action("oP6","highlight")
_UIA_Action("oP6","setfocus")
;~_UIA_Action("oP7","highlight")
_UIA_Action("oP7","setfocus")
;~_UIA_Action("oP8","highlight")
_UIA_Action("oP8","setfocus")

_UIA_action("oUIElement","highlight")
_UIA_action("oUIElement","click")

 

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites

If you do this the op  will omit to care about the parent children windows focus. 

 

Anyway. It was obvius ;).

Edited by caramen

My video tutorials : HERE ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites

He just used the IUIAutomation UDF. That is allowing you to automate.net windows that autoIT cannot automate.

 

This UDF request some training. 

 

Mail you can search in my precedent posts. 

 

I have a topic named IUIAutomation learning. 

It will show you how i learned it and what issue i encoutered and how i resolved them. 

 

You will have to face on this if you want to use IUIA UDF.

 

Here you go : 

 

Edited by caramen

My video tutorials : HERE ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites

yeah, run simplespy, move your mouse over the app and press Ctrl-W, then paste the code to your AutoIt editor and start playing around. IUIAutomation is not really that difficult when you figure out what you looking for.

I suggest going through all the examples and getting stuff to work and start learning that way.

if you need more help, post back.

 

One thing I have done to really get into @junkew's IUIAutomation is study his actual UDF code. it's a gold mine. but that comes later, for now, get the samples to work, we can help with that. post back if you need help.

 

That Dolomites program is pretty cool actually. Playing with coils... sweet.

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...