Jump to content

How to automate button click in a GUI?


Recommended Posts

38 minutes ago, Iulia_Vascan said:

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

#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_TreeControlTypeId;class:=") ;

;~ $oUIElement=_UIA_getObjectByFindAll("Windingn.1Q=242p=4m=3.mainwindow", "title:=Winding n. 1 Q = 24 2p = 4 m = 3;ControlType:=UIA_TreeItemControlTypeId", $treescope_subtree)
_UIA_setVar("oUIElement","Title:=Winding n. 1 Q = 24 2p = 4 m = 3;controltype:=UIA_TreeItemControlTypeId;class:=") ;ControlType:=UIA_TreeItemControlTypeId;classname:=")


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

so I just used the wizard to create an example, but this worked for me. just type out the name, you may have to create the name using the user input however, I am not sure how you are getting the name. In my case it's 

Winding n. 1 Q = 24 2p = 4 m = 3

 

you could build that string with the collected data from the user is what I was trying to say. also, you can double click if by doing this

_UIA_action("oUIElement","doubleclick")

 

that easy, works here on my system. let me know if you need more assistance. at this point it is based off number of phases (m=3) Number of slots (Q=24) and the winding number, which is just increaing.

Look at the string functions to build strings for use with the IUI kit

you should be able to get those values easily

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

Solution 1 = regular expression

_UIA_setVar("oUIElement","Title:=> Winding.*;controltype:=UIA_ButtonControlType")

Soluition 1b use regex plus index property if it recognizes multiple elements

Solution 2 use indexrelative which you can use to go n elements further or with -n elements before another known element thats more static in property identification.

Solution 3 use string functions to construct your string to recognize.

Solution 4 see if the button has an automationid thats static. I doubt as i see its a qtwidget.

 

Link to comment
Share on other sites

@junkew Is it possible to hide all my process of automation in the background, so the user don't see all the steps that the script does ? I found in the macro reference @SH_HIDE which hides the window.

Run("C:\Users\UTCN-MAE\Desktop\M_2\dolomites-release-python\Dolomites.exe", @SH_HIDE)

The window is hidden but the code is no longer working. Is is because this function (_UIA_Action) needs to have the window of the GUI on the screen? Because I saw that if the window is hidden the code is searching on my screen after the buttons.

 

;~ *** Standard code maintainable ***
Run("C:\Users\UTCN-MAE\Desktop\M_2\dolomites-release-python\Dolomites.exe")
WinWaitActive("[CLASS:Dolomites]", "", 1)

#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("Add mainwindow", "title:=Add;ControlType:=UIA_ButtonControlTypeId", $treescope_subtree)
_UIA_setVar("oUIElement","Title:=Add;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")

;~ $oUIElement=_UIA_getObjectByFindAll("Add mainwindow", "title:=Add;ControlType:=UIA_ButtonControlTypeId", $treescope_subtree)
_UIA_setVar("oUIElement","Title:= Winding n. .*;controltype:=UIA_ButtonControlType") ;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")

;~ $oUIElement=_UIA_getObjectByFindAll("Add mainwindow", "title:=Add;ControlType:=UIA_ButtonControlTypeId", $treescope_subtree)
_UIA_setVar("oUIElement","Title:=GetDP circuit;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")

WinWaitActive("[CLASS:Dolomites]", "", 1)
ControlFocus("Save GetDP circuit", "", "Edit1")
ControlSetText("Save GetDP circuit", "", "Edit1", "C:\Users\UTCN-MAE\Desktop\M_2\Windings\winding.txt",@SW_HIDE)
ControlClick("Save GetDP circuit", "","Button2")
WinWaitActive("[CLASS:Dolomites]", "", 1)
If ProcessExists("Dolomites.exe") Then
    ProcessClose("Dolomites.exe")
EndIf

Run("C:\Users\UTCN-MAE\Desktop\M_2\onelab-Windows64\gmsh.exe")
WinWaitActive("[CLASS:FLTK]", "", 1)

 

Link to comment
Share on other sites

No ui stands for user interface as soon as you hide it ts not availabe for x y coordinates etc.  The whole concept is around userinteraction. You could hide it when you run a virtual machine or maybe virtual displaydrivers but that are in general complexer solutions.

Link to comment
Share on other sites

@Iulia_Vascan

If you want to do all those steps without using UI Automation UDF, you could use the built-in scripting library of Dolomites, through which you can do whatever you want ( even interact with the user combining AutoIt and Python ), as I have already suggested you in PM :)

It is well documented, and it allows you to do whatever you do through UI, and even more.

That should be even better than automating the UI :)

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

  • 1 year later...
On 10/30/2018 at 3:56 PM, Earthshine said:

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.

" the other theory is that they are not windows controls "??🙄🙄🤦🏻‍♂️...if they are not "WINDOWS CONTROLS"..then what do you call them? 🤐

all i can see here is " only words with no sense "...they say "The worst wheel of the cart makes the most noise."😏

Link to comment
Share on other sites

  • Developers

Guys could you take this somewhere else and @Ghoul2020, why on earth so you bother us with your shit? Just don't post when you can handle somebody strong king back at you after you lash out. 

 

Jos

 

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

4 hours ago, Jos said:

Guys could you take this somewhere else and @Ghoul2020, why on earth so you bother us with your shit? Just don't post when you can handle somebody strong king back at you after you lash out

 

Jos

 

Listen KID😄 ..I don't know if you understand this ..BUT..

I have a hard time arguing with STUPID people...I feel like I've lost so many amazing traits because I've listened to stupid people, ignorant people who are bullies.
They should have to wear signs that just say, 'I'm STUPID.'...🖕🏻

Link to comment
Share on other sites

  • Moderators

 Ghoul2020,

We try to keep these forums a civilised place and so reactions like yours above do not sit nicely here. Furthermore replying as you did to a member of the Moderation team is extremely unwise.

I have locked the thread but, because of your newness here I will limit my actions to just that. Consider yourself very lucky and change your attitude in any future posts as you have now used up any flex we were prepared to show you. Any further transgressions will lead to your immediate removal from the community. Your choice - please choose wisely.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Developers
5 hours ago, Ghoul2020 said:

Listen KID😄 ..I don't know if you understand this ..BUT..

mmmm KID?

You have received a final warning to either clean up your act here or you will be shipped out permanently. 😒

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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