Jump to content

Recommended Posts

Posted

I'm trying ot use controlClick to click on button. So I'm using the Window Info Finder tool. But I noticed that the control ID in windowInfo changes each time I restart the app.  

Am I doing this wrong.

Posted

Its Probably the app you are trying to automate is there something else unique about the button like a specific class name to it?

Local $hWnd = WinWait("[Title:Calculator; CLASS:CalcFrame; INSTANCE:1]")
ConsoleWrite("Calc hWnd =" & $hWnd & @CRLF)


Local $iRes = ControlClick($hWnd, "", "[CLASS:Button; INSTANCE:" & GetCtrlInstanceFromText($hWnd, "CE") & "]", "left", 1) ; CE Button
If $iRes Then $iRes = ControlClick($hWnd, "", "[CLASS:Button; INSTANCE:" & GetCtrlInstanceFromText($hWnd, "7") & "]", "left", 7) ;7 Button
If $iRes Then $iRes = ControlClick($hWnd, "", "[CLASS:Button; INSTANCE:" & GetCtrlInstanceFromText($hWnd, "+") & "]", "left", 1) ; + Button
If $iRes Then $iRes = ControlClick($hWnd, "", "[CLASS:Button; INSTANCE:" & GetCtrlInstanceFromText($hWnd, "3") & "]", "left", 1) ; 3 Button
If $iRes Then $iRes = ControlClick($hWnd, "", "[CLASS:Button; INSTANCE:" & GetCtrlInstanceFromText($hWnd, "=") & "]", "left", 1) ; = Button
ConsoleWrite("Success = " & $iRes & @CRLF) ;Didn't Work :(

Local $iRes = ControlClick($hWnd, "", "[CLASS:Button; ID:" & "82" & "]", "left", 1) ; CE Button
If $iRes Then $iRes = ControlClick($hWnd, "", "[CLASS:Button; ID:" & "135" & "]", "left", 7) ;5 Button
If $iRes Then $iRes = ControlClick($hWnd, "", "[CLASS:Button; ID:" & "93" & "]", "left", 1) ; + Button
If $iRes Then $iRes = ControlClick($hWnd, "", "[CLASS:Button; ID:" & "131" & "]", "left", 1) ; 1 Button
If $iRes Then $iRes = ControlClick($hWnd, "", "[CLASS:Button; ID:" & "121" & "]", "left", 1) ; = Button
ConsoleWrite("Success = " & $iRes & @CRLF)

Func GetCtrlInstanceFromText($hWnd, $sCtrlText)
    Local $iInstance = -1
    Local $iErr = 0
    Local $sText
    For $i = 0 To 100
        $sText = ControlGetText($hWnd, "", "[CLASS:Button; INSTANCE:" & $i & "]")
        If @error Then
            ConsoleWrite("Skipped: " & $i & @CRLF)
            ContinueLoop
        ElseIf StringInStr($sText, $sCtrlText) Then
            ConsoleWrite("Found: " & $sText & @CRLF)
            $iInstance = $i
            ExitLoop
        Else
            ConsoleWrite($sText & " Instance: " & $i & @CRLF)
        EndIf
    Next

    Return $iInstance
EndFunc

Now note that the first try should be called like this for each

ControlClick($hWnd, "", "[CLASS:Button; TEXT:CE]")
Not
ControlClick($hWnd, "", "[CLASS:Button; INSTANCE:" & GetCtrlInstanceFromText($hWnd, "CE") & "]"

I just expanded a different example and wanted you to see the inner workings

https://www.autoitscript.com/autoit3/docs/intro/controls.htm

Barring the other options You could try going through all instances till you get one at a particular coordinate

And Finally you could resort through looking for the button with a pixel search

 

Posted

Thanks guys. Bilgus, I'll check that out.

I tried using this

ControlClick('Innovaya Studio', '', "[CLASS:WindowsForms10.Window.8.app.0.1e84ccb_r16_ad1; TEXT:Open; INSTANCE:10]").

But no luck.  The class name seems weird.  Maybe it won't work becuase its not a standard ms control??  Heres the image from winInfo:

image.png.33ca5b9777ae16fe7358f77c1e7263fd.png

Posted

On that control the developers have helpfully provided a name for the button, I would recommend that you use that. It should work reliably

ControlClick('Innovaya Studio', '', "[NAME:butOpenInv]")

 

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Posted

image.png.f3889dbdfdc0a2bb06bcf85cc7f6d610.png

52 minutes ago, Bowmore said:

On that control the developers have helpfully provided a name for the button, I would recommend that you use that. It should work reliably

ControlClick('Innovaya Studio', '', "[NAME:butOpenInv]")

 

[Name:butOpenInv] works great.  I have a separate problem now.  If i use this script I can start the program, but autoIt cannot complete the block of code to click 'Open' button.  But if I comment out the first 'Run' line command and manually start the app then run the script it works fine.  I'm confused why??

 

Posted
14 minutes ago, Earthshine said:

Oh boy. Win 10. You may have to use our UI automation

I thought thats what I was doing?? :)

Posted (edited)

I think that @Sw_ShowMaximized should be

@SW_MAXIMIZE

 

also WinWait, WinActive, WinActivate..... Returns a hWnd

Run("......", "", @SW_MAXIMIZED)
Local $iTRy = 0
Local $hWnd = 0 

$hWnd = WinWait("Innovaya Studio","", 12)
If Not $hWnd Then
    Msgbox(0,"Error", "Window is not Found")
    Exit
Else
    WinActivate($hWnd)
Endif

ControlClick($hWnd, '', "[NAME:butOpenInv]")

 

Edited by Bilgus
Posted
19 hours ago, Bilgus said:

I think that @Sw_ShowMaximized should be

@SW_MAXIMIZE

 

also WinWait, WinActive, WinActivate..... Returns a hWnd

Run("......", "", @SW_MAXIMIZED)
Local $iTRy = 0
Local $hWnd = 0 

$hWnd = WinWait("Innovaya Studio","", 12)
If Not $hWnd Then
    Msgbox(0,"Error", "Window is not Found")
    Exit
Else
    WinActivate($hWnd)
Endif

ControlClick($hWnd, '', "[NAME:butOpenInv]")

 

After using this code AutoIt still cannot get past the inital run command.  If I run the scipt it starts the app, then stops.  If I then comment out the run command the script works perfectly.  I wonder why autoIt gets stuck??

Posted (edited)

also, try just a WinWaitActive for waiting for your application. please, also post your CODE, not images of your code. that is super annoying and I am not going to type all that in to test or edit.

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Posted
27 minutes ago, Earthshine said:

snip

Having the following values for all properties: 
Title is: <Open>    Class   := <WindowsForms10.Window.b.app.0.1e84ccb_r16_ad1>    controltype:= <UIA_ButtonControlTypeId>    ,<50000>    , (0000C350)    9;65;131;63
*** Parent Information top down ***
2: Title is: <Innovaya Studio>    Class   := <WindowsForms10.Window.8.app.0.1e84ccb_r16_ad1>    controltype:= <UIA_WindowControlTypeId>    ,<50032>    , (0000C370)    -8;-8;1616;876
"Title:=Innovaya Studio;controltype:=UIA_WindowControlTypeId;class:=WindowsForms10.Window.8.app.0.1e84ccb_r16_ad1""    
1: Title is: <panelMRF>    Class   := <WindowsForms10.Window.8.app.0.1e84ccb_r16_ad1>    controltype:= <UIA_PaneControlTypeId>    ,<50033>    , (0000C371)    0;55;1600;805
"Title:=panelMRF;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.1e84ccb_r16_ad1""    
0: Title is: <panelOpenExit>    Class   := <WindowsForms10.Window.8.app.0.1e84ccb_r16_ad1>    controltype:= <UIA_PaneControlTypeId>    ,<50033>    , (0000C371)    2;57;143;801
"Title:=panelOpenExit;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.1e84ccb_r16_ad1""    


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

_UIA_setVar("oP1","Title:=Innovaya Studio;controltype:=UIA_WindowControlTypeId;class:=WindowsForms10.Window.8.app.0.1e84ccb_r16_ad1")    ;Innovaya Studio
_UIA_setVar("oP2","Title:=panelMRF;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.1e84ccb_r16_ad1")    ;panelMRF
_UIA_setVar("oP3","Title:=panelOpenExit;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.1e84ccb_r16_ad1")    ;panelOpenExit

_UIA_setVar("Open.mainwindow","title:=Open;classname:=WindowsForms10.Window.b.app.0.1e84ccb_r16_ad1")

;~ 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("Open.mainwindow","setfocus")


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

Local $oP2=_UIA_getObjectByFindAll($UIA_oDesktop, "Title:=Innovaya Studio;controltype:=UIA_WindowControlTypeId;class:=WindowsForms10.Window.8.app.0.1e84ccb_r16_ad1", $treescope_children)    
_UIA_Action($oP2,"setfocus")
Local $oP1=_UIA_getObjectByFindAll($oP2, "Title:=panelMRF;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.1e84ccb_r16_ad1", $treescope_children)    
_UIA_Action($oP1,"setfocus")
Local $oP0=_UIA_getObjectByFindAll($oP1, "Title:=panelOpenExit;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.1e84ccb_r16_ad1", $treescope_children)    
_UIA_Action($oP0,"setfocus")
_UIA_setVar("Open.mainwindow","title:=Open;classname:=WindowsForms10.Window.b.app.0.1e84ccb_r16_ad1")
_UIA_action("Open.mainwindow","setfocus")


*** Detailed properties of the highlighted element ***
UIA_title:= <Open>
UIA_text:= <Open>
UIA_regexptitle:= <Open>
UIA_class:= <WindowsForms10.Window.b.app.0.1e84ccb_r16_ad1>
UIA_regexpclass:= <WindowsForms10.Window.b.app.0.1e84ccb_r16_ad1>
UIA_iaccessiblechildId:= <0>
UIA_id:= <butOpenInv>
UIA_handle:= <136658>
UIA_RuntimeId:= <42;136658>
UIA_BoundingRectangle:= <9;65;131;63>
UIA_ProcessId:= <8972>
UIA_ControlType:= <50000>
UIA_LocalizedControlType:= <button>
UIA_Name:= <Open>
UIA_HasKeyboardFocus:= <False>
UIA_IsKeyboardFocusable:= <False>
UIA_IsEnabled:= <True>
UIA_AutomationId:= <butOpenInv>
UIA_ClassName:= <WindowsForms10.Window.b.app.0.1e84ccb_r16_ad1>
UIA_Culture:= <0>
UIA_IsControlElement:= <True>
UIA_IsContentElement:= <True>
UIA_IsPassword:= <False>
UIA_NativeWindowHandle:= <136658>
UIA_IsOffscreen:= <False>
UIA_Orientation:= <0>
UIA_FrameworkId:= <WinForm>
UIA_IsRequiredForForm:= <False>
UIA_IsDockPatternAvailable:= <False>
UIA_IsExpandCollapsePatternAvailable:= <False>
UIA_IsGridItemPatternAvailable:= <False>
UIA_IsGridPatternAvailable:= <False>
UIA_IsInvokePatternAvailable:= <True>
UIA_IsMultipleViewPatternAvailable:= <False>
UIA_IsRangeValuePatternAvailable:= <False>
UIA_IsScrollPatternAvailable:= <False>
UIA_IsScrollItemPatternAvailable:= <False>
UIA_IsSelectionItemPatternAvailable:= <False>
UIA_IsSelectionPatternAvailable:= <False>
UIA_IsTablePatternAvailable:= <False>
UIA_IsTableItemPatternAvailable:= <False>
UIA_IsTextPatternAvailable:= <False>
UIA_IsTogglePatternAvailable:= <False>
UIA_IsTransformPatternAvailable:= <False>
UIA_IsValuePatternAvailable:= <False>
UIA_IsWindowPatternAvailable:= <False>
UIA_ValueIsReadOnly:= <True>
UIA_RangeValueValue:= <0>
UIA_RangeValueIsReadOnly:= <True>
UIA_RangeValueMinimum:= <0>
UIA_RangeValueMaximum:= <0>
UIA_RangeValueLargeChange:= <0>
UIA_RangeValueSmallChange:= <0>
UIA_ScrollHorizontalScrollPercent:= <0>
UIA_ScrollHorizontalViewSize:= <100>
UIA_ScrollVerticalScrollPercent:= <0>
UIA_ScrollVerticalViewSize:= <100>
UIA_ScrollHorizontallyScrollable:= <False>
UIA_ScrollVerticallyScrollable:= <False>
UIA_SelectionCanSelectMultiple:= <False>
UIA_SelectionIsSelectionRequired:= <False>
UIA_GridRowCount:= <0>
UIA_GridColumnCount:= <0>
UIA_GridItemRow:= <0>
UIA_GridItemColumn:= <0>
UIA_GridItemRowSpan:= <1>
UIA_GridItemColumnSpan:= <1>
UIA_DockDockPosition:= <5>
UIA_ExpandCollapseExpandCollapseState:= <3>
UIA_MultipleViewCurrentView:= <0>
UIA_WindowCanMaximize:= <False>
UIA_WindowCanMinimize:= <False>
UIA_WindowWindowVisualState:= <0>
UIA_WindowWindowInteractionState:= <0>
UIA_WindowIsModal:= <False>
UIA_WindowIsTopmost:= <False>
UIA_SelectionItemIsSelected:= <False>
UIA_TableRowOrColumnMajor:= <2>
UIA_ToggleToggleState:= <2>
UIA_TransformCanMove:= <False>
UIA_TransformCanResize:= <False>
UIA_TransformCanRotate:= <False>
UIA_IsLegacyIAccessiblePatternAvailable:= <True>
UIA_LegacyIAccessibleChildId:= <0>
UIA_LegacyIAccessibleName:= <Open>
UIA_LegacyIAccessibleRole:= <43>
UIA_LegacyIAccessibleState:= <0>
UIA_LegacyIAccessibleDefaultAction:= <Press>
UIA_IsDataValidForForm:= <False>
UIA_ProviderDescription:= <[pid:8568,hwnd:0x215D2 Main:Nested [pid:8972,hwnd:0x215D2 Main(parent link):Microsoft: MSAA Proxy (unmanaged:uiautomationcore.dll)]; Hwnd(parent link):Microsoft: HWND Proxy (unmanaged:uiautomationcore.dll)]>
UIA_IsItemContainerPatternAvailable:= <False>
UIA_IsVirtualizedItemPatternAvailable:= <False>
UIA_IsSynchronizedInputPatternAvailable:= <False>

Posted

AutoItSetOption('MouseCoordMode', 0)
AutoItSetOption('SendKeyDelay', 10)

;Start Innovaya Studio
Run("c:\Program Files\Innovaya\R4\inv5d.exe", "", @SW_MAXIMIZE)
Local $iTRy = 0
Local $hWnd = 0

$hWnd = WinWaitActive('Innovaya Studio', '', 10)
If Not $hWnd Then
   MsgBox(0, "Error", "window is not found")
   Exit
Else
   WinActivate($hWnd)
EndIf

ControlClick($hWnd, '', '[NAME:butOpenInv]')

;choose file to open
WinWait('Select an INVx File')
WinActivate('Select an INVx File')
ControlClick('Select an INVx File', '', 1148)
Send('C:\Innovaya\Models\INVx\Innovaya\Archtectural 2017_V1.invx')
Send("{ENTER}")

;Load File
WinWait('Archtectural 2017_V1.invx')
WinActivate('Archtectural 2017_V1.invx')
Send("{ENTER}")

;Click ok to continue
WinWait('INV project has successfully been loaded')
WinActivate('INV project has successfully been loaded')
Send("{ENTER}")

;Enter to continue
;WinWait('Export Quantities to Excel')
;WinActivate('Export Quantities to Excel')
;Send("{ENTER}")

WinWait('Quantity Extraction')
WinActivate('Quantity Extraction')
Send("{ENTER}")

WinWait('Export Quantities to Excel')
WinActivate('Export Quantities to Excel')
Send("{ENTER}")

WinWait('Quantities Report Complete')
WinActivate('Quantities Report Complete')
Send("{ENTER}")

WinWait('Microsoft Excel - Sheet1')
WinActivate('Microsoft Excel - Sheet1')
MouseClick('primary', 1063, 22, 1, 0)
WinClose("[LAST]")

 

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