Jump to content

How to automate button click in a GUI?


Recommended Posts

13 minutes ago, Earthshine said:

That Dolomites program is pretty cool actually.

Pm information requested since i noticed the pole button :P ? 

PM me what is this soft usage ? 

My video tutorials : ( 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

 

Link to comment
Share on other sites

On 10/30/2018 at 6:07 AM, Iulia_Vascan said:

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

the add button is very similar as captured by simplespy.au3, here both buttons are clicked, but you must select a windings first for the second button to do anything. right now, it just presses Add and then  Export GetDP

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

_UIA_setVar("oUIElementAdd","Title:=Add;controltype:=UIA_ButtonControlTypeId;class:=")
_UIA_action("oUIElementAdd","highlight")
_UIA_action("oUIElementAdd","click")

_UIA_setVar("oUIElementGet","Title:=Export GetDP circuit;controltype:=UIA_ButtonControlTypeId;class:=") 
_UIA_action("oUIElementGet","highlight")
_UIA_action("oUIElementGet","click")

 

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

@Earthshine Hi again, I tried to run your script, and every time I run it, I get this error. I found some explanation on this forum, but it's not working.. the problem it will be the "_" underscore, I delete them but still not working...

">"C:\Program Files (x86)\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "E:\Iulia_Vascan\Metoda_2\au3_uiautomation-master\simple_2.au3"    
"E:\Iulia_Vascan\Metoda_2\au3_uiautomation-master\simple_2.au3" (5) : ==> Unknown function name.:
_UIA_setVar("oUIElementAdd","Title:=Add;controltype:=UIA_ButtonControlTypeId;class:=")
^ ERROR
>Exit code: 1    Time: 0.1101"

 

;~ *** 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")

 

Link to comment
Share on other sites

@Iulia_Vascan

If you click on the file of the include ( .au3 ), and then press Ctrl + I, you'll open the include file, in which you should find _UIA_setVar() function.

Maybe it is called in another way, or maybe you have to include another "library" :)

 

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

Read this carefully to see how to change your registry so that your uiwrappers.au3 does not have to be in same folder as your script

https://www.autoitscript.com/autoit3/docs/keywords/include.htm

simplespy generates generic identification so if you have empty on properties

Title:=;controltype:=UIA_CustomControlTypeId;class:=

you can change it to

controltype:=UIA_CustomControlTypeId

which will only work if there is one control or its the first on this level

Link to comment
Share on other sites

Or you could try a simpler form of mouse clicks :

Opt ("PixelCoordMode", 0) 
Opt ("MouseCoordMode", 0)
Opt ("MustDeclareVars", 1)
Run("E:\Iulia_Vascan\dolomites-release-python\Dolomites.exe")
WinWaitActive ("Dolomites")
MouseClick ("left",215,298,1,5) ; add buton
Sleep (250)
MouseClick ("left",307,59,1,5) ; get dp button
Sleep (250)
....

 

Edited by Nine
Link to comment
Share on other sites

17 minutes ago, Earthshine said:

what if dolomites runs somewhere else on the screen? this is more reliable that that stuff. user can change the size and location of the window and it would still work if those controls could be gotten to.

Opt ("PixelCoordMode", 0) 
Opt ("MouseCoordMode", 0)
 

That solves the problem ! MouseClick is then relative the current active window.  No matter where the window is located it will work unless the button changes place :s

Link to comment
Share on other sites

Link to comment
Share on other sites

2 hours ago, FrancescoDiMuro said:

You're right, but think that the dynamics that the script has with UI Automation will never be like mouse clicks

I prefer a 6 lines of code that works that 100 lines that doesn't work

It is easy to fall into a dogmatic approach, it is harder to get out...

Edited by Nine
Link to comment
Share on other sites

Be aware uiawrappers can go from simple to complex for hundreds of screens in a more maintainable way to even splitting your recognition strings in a separate config file.

For a few buttons you could use x y mouseclick but if your app redesigns the ui you have a lot of work when it are dozens of mouseclicks.

With mouseclick you do the job of finding x y. With recognition strings the computer does the job of finding x y either controlclick or uia or other udf.

Link to comment
Share on other sites

Hi again, 

I automated those two buttons, but now I have a problem with another one which is more complicated, because its name depends on the user input.

 More precise here in Dolomites software, the user inserts some input variables (Q=var1=? , 2p=var2=? and m=var3=?), then with AutoIT  the Add button is pushed, after that the winding is generated with the name "Winding n. 1 Q= var1 2p= var2 m= var3" and I have to select this button (picture below). I can add this button in the script as the Add button, but here is the problem... The script doesn't know what variables the user will insert. So I have to push the button "Winding n. 1 Q= ? 2p= ? m= ?". Is a posibility that AutoIT to identify this button if it knows just a part of name's button? I tried just with "Winding n. 1 Q=  2p=  m= " but it doesn't recognize the button and it stops. 

_UIA_setVar("oUIElement","Title:=> Winding n. 1 Q=  2p=  m=;controltype:=UIA_ButtonControlTypeId;class:=")

How can I automate the push of this button if the name depends on what the user will insert?

a1.png

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...