Docfxit Posted February 15, 2019 Share Posted February 15, 2019 I'm having trouble selecting this button: This is what I have tried: WinWait("HomeSeer HS3", "Get FREE Trial Licen") If Not WinActive("HomeSeer HS3", "Get FREE Trial Licen") Then WinActivate("HomeSeer HS3", "Get FREE Trial Licen") WinWaitActive("HomeSeer HS3", "Get FREE Trial Licen") ;Send("{TAB}{ENTER}") ;ControlClick("HomeSeer HS3", "Get FREE Trial Licen", "[CLASSNN:WindowsForms10.Window.8.app.0.141b42a_r14_ad12]") ControlClick("HomeSeer HS3", "Get FREE Trial Licen", "[ID:1051746]") Thanks, Docfxit Link to comment Share on other sites More sharing options...
caramen Posted February 15, 2019 Share Posted February 15, 2019 Hi, could you try that ? If Not $hWND = WinActive("HomeSeer HS3", "Get FREE Trial Licen") Then $hWND = WinActivate("HomeSeer HS3", "") WinWaitActive( $hWND , "") ControlClick( $hWND , "", "[CLASS:WindowsForms10.BUTTON.app.0.141b42a_r14_ad1; INSTANCE:2]" ,"left",1 ) 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 - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki Link to comment Share on other sites More sharing options...
Docfxit Posted February 15, 2019 Author Share Posted February 15, 2019 I tried your suggestion. It didn't work. Thanks you very much for taking a stab at it. I don't understand why any of these don't work. Thanks, Docfxit Link to comment Share on other sites More sharing options...
LarsJ Posted February 15, 2019 Share Posted February 15, 2019 Many especially new and modern-style applications cannot be automated with classic code. You need UI Automation code that has been Microsoft's automation platform for the last 15 years. See Using UI Automation Code in AutoIt. Then use one of the spy tools to check if UIA-code can identify the controls in the window. Add a new post if you need more help. Earthshine 1 Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
Docfxit Posted February 15, 2019 Author Share Posted February 15, 2019 Thanks for pointing me in the right direction. I found a really cool spy tool called UIASpy. Great work LarsJ. I'd like to click a button. I found an example called "Click a button control:" $oSave.GetCurrentPattern( $UIA_InvokePatternId, $pInvoke ) $oInvoke = ObjCreateInterface( $pInvoke, $sIID_IUIAutomationInvokePattern, $dtagIUIAutomationInvokePattern ) If Not IsObj( $oInvoke ) Then Return ConsoleWrite( "$oInvoke ERR" & @CRLF ) ConsoleWrite( "$oInvoke OK" & @CRLF ) $oInvoke.Invoke() How can I apply that to my button? expandcollapse popupTreeview Element Pane: Register Now... Element Properties (identification) $UIA_ClassNamePropertyId WindowsForms10.BUTTON.app.0.141b42a_r14_ad1 $UIA_ControlTypePropertyId $UIA_PaneControlTypeId $UIA_NamePropertyId Register Now... Element Properties (session unique) $UIA_NativeWindowHandlePropertyId 0x00070C84 $UIA_ProcessIdPropertyId 1852 $UIA_RuntimeIdPropertyId 42,461956 Element Properties (information) $UIA_BoundingRectanglePropertyId l=1273,t=573,w=142,h=28 $UIA_FrameworkIdPropertyId WinForm $UIA_LocalizedControlTypePropertyId pane $UIA_ProviderDescriptionPropertyId [pid:6428,hwnd:0x70C84 Annotation:Microsoft: Annotation Proxy (unmanaged:uiautomationcore.dll); Main:Microsoft: MSAA Proxy (unmanaged:uiautomationcore.dll); Hwnd(parent link):Microsoft: HWND Proxy (unmanaged:uiautomationcore.dll)] Element Properties (has/is info) $UIA_HasKeyboardFocusPropertyId False $UIA_IsContentElementPropertyId True $UIA_IsControlElementPropertyId True $UIA_IsDataValidForFormPropertyId False $UIA_IsEnabledPropertyId True $UIA_IsKeyboardFocusablePropertyId True $UIA_IsOffscreenPropertyId False $UIA_IsPasswordPropertyId False $UIA_IsRequiredForFormPropertyId False Control Patterns (element actions) $UIA_IsLegacyIAccessiblePatternAvailablePropertyId True Control Pattern Properties $UIA_LegacyIAccessibleChildIdPropertyId 0 $UIA_LegacyIAccessibleDefaultActionPropertyId $UIA_LegacyIAccessibleDescriptionPropertyId $UIA_LegacyIAccessibleHelpPropertyId $UIA_LegacyIAccessibleKeyboardShortcutPropertyId $UIA_LegacyIAccessibleNamePropertyId Register Now... $UIA_LegacyIAccessibleRolePropertyId 10 = $ROLE_SYSTEM_CLIENT $UIA_LegacyIAccessibleStatePropertyId 1048576 = $STATE_SYSTEM_FOCUSABLE $UIA_LegacyIAccessibleValuePropertyId Control Pattern Methods LegacyIAccessible Pattern Methods DoDefaultAction() Select(long) SetValue(wstr) GetIAccessible(idispatch*) CurrentChildId(int*) CurrentDefaultAction(bstr*) CurrentDescription(bstr*) CurrentHelp(bstr*) CurrentKeyboardShortcut(bstr*) CurrentName(bstr*) CurrentRole(uint*) CurrentState(uint*) CurrentValue(bstr*) GetCurrentSelection(ptr*) Parents from Desktop Pane: Desktop Window: HomeSeer HS3 Parent to child index 6 Thanks, Docfxit Link to comment Share on other sites More sharing options...
Docfxit Posted February 15, 2019 Author Share Posted February 15, 2019 (edited) I'm not sure I'm going in the correct direction but I found an explanation on how to create sample code. Really cool.... So I'm getting these errors. I'm guessing there must be something I'm supposed to include before this code. I must be missing something very simple. Docfxit Edited February 15, 2019 by Docfxit Link to comment Share on other sites More sharing options...
LarsJ Posted February 15, 2019 Share Posted February 15, 2019 (edited) Docfxit, The control that you have identified is a pane control (broadly similar to a window). I think there should be a real button control either as a parent or child of the pane control. Would you please check it out and show the information for the button. You can right-click the "HomeSeer HS3" window and then click "Update all childs of item". Regards Lars. This is postet before I've read your last post. The sample code is somewhat generic code. It's not directly runnable. You have to do some corrections. But info about the button is more important. Edited February 15, 2019 by LarsJ Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
Docfxit Posted February 15, 2019 Author Share Posted February 15, 2019 (edited) Thank you for the directions... After the update this is what I get: expandcollapse popupTreeview Element Pane: Register Now... Element Properties (identification) $UIA_ClassNamePropertyId WindowsForms10.BUTTON.app.0.141b42a_r14_ad1 $UIA_ControlTypePropertyId $UIA_PaneControlTypeId $UIA_NamePropertyId Register Now... Element Properties (session unique) $UIA_NativeWindowHandlePropertyId 0x00070C84 $UIA_ProcessIdPropertyId 1852 $UIA_RuntimeIdPropertyId 42,461956 Element Properties (information) $UIA_BoundingRectanglePropertyId l=1273,t=573,w=142,h=28 $UIA_FrameworkIdPropertyId WinForm $UIA_LocalizedControlTypePropertyId pane $UIA_ProviderDescriptionPropertyId [pid:6428,hwnd:0x70C84 Annotation:Microsoft: Annotation Proxy (unmanaged:uiautomationcore.dll); Main:Microsoft: MSAA Proxy (unmanaged:uiautomationcore.dll); Hwnd(parent link):Microsoft: HWND Proxy (unmanaged:uiautomationcore.dll)] Element Properties (has/is info) $UIA_HasKeyboardFocusPropertyId False $UIA_IsContentElementPropertyId True $UIA_IsControlElementPropertyId True $UIA_IsDataValidForFormPropertyId False $UIA_IsEnabledPropertyId True $UIA_IsKeyboardFocusablePropertyId True $UIA_IsOffscreenPropertyId False $UIA_IsPasswordPropertyId False $UIA_IsRequiredForFormPropertyId False Control Patterns (element actions) $UIA_IsLegacyIAccessiblePatternAvailablePropertyId True Control Pattern Properties $UIA_LegacyIAccessibleChildIdPropertyId 0 $UIA_LegacyIAccessibleDefaultActionPropertyId $UIA_LegacyIAccessibleDescriptionPropertyId $UIA_LegacyIAccessibleHelpPropertyId $UIA_LegacyIAccessibleKeyboardShortcutPropertyId $UIA_LegacyIAccessibleNamePropertyId Register Now... $UIA_LegacyIAccessibleRolePropertyId 10 = $ROLE_SYSTEM_CLIENT $UIA_LegacyIAccessibleStatePropertyId 1048576 = $STATE_SYSTEM_FOCUSABLE $UIA_LegacyIAccessibleValuePropertyId Control Pattern Methods LegacyIAccessible Pattern Methods DoDefaultAction() Select(long) SetValue(wstr) GetIAccessible(idispatch*) CurrentChildId(int*) CurrentDefaultAction(bstr*) CurrentDescription(bstr*) CurrentHelp(bstr*) CurrentKeyboardShortcut(bstr*) CurrentName(bstr*) CurrentRole(uint*) CurrentState(uint*) CurrentValue(bstr*) GetCurrentSelection(ptr*) Parents from Desktop Pane: Desktop Window: HomeSeer HS3 Parent to child index 6 Thanks, Docfxit Edited February 15, 2019 by Docfxit Link to comment Share on other sites More sharing options...
LarsJ Posted February 15, 2019 Share Posted February 15, 2019 This is still the pane control: Treeview Element Pane: Register Now... I would like to see info about a button control. Try something else. Right-click the "HomeSeer HS3" window in the treeview and then click "Update all childs of item". Right-click the "HomeSeer HS3" window again and then click "Copy structure to clipboard". Show the info. Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
Docfxit Posted February 15, 2019 Author Share Posted February 15, 2019 That's really nice of you to help me with this. You must have spent countless hours creating UIASpy. 0000 Window: HomeSeer HS3 0001 Pane: Get FREE Trial License 0002 Pane: Version 3.0.0.500 0003 Pane: Please Register to Use or 0004 Pane: ----- 0005 Pane: ----- 0006 Pane: Upgrade to PRO 0007 Pane: Register Now... 0008 Pane: Continue Trial 0009 Pane: Errors/Warnings: 0010 Pane: Web Interface 0011 Pane: Startup Log 0012 Pane: WindowsForms10.EDIT.app.0.141b42a_r14_ad1 0013 Pane: WindowsForms10.Window.8.app.0.141b42a_r14_ad1 0014 Pane: WindowsForms10.msctls_progress32.app.0.141b42a_r14_ad1 0015 TitleBar Link to comment Share on other sites More sharing options...
LarsJ Posted February 15, 2019 Share Posted February 15, 2019 (edited) OK, there is only a pane control. That's the reason why you can't identify it with classic automation. It's very late in Copenhagen. I'll be back tomorrow. Edited February 15, 2019 by LarsJ Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
Docfxit Posted February 15, 2019 Author Share Posted February 15, 2019 Thanks for your help. Docfxit Link to comment Share on other sites More sharing options...
Docfxit Posted February 15, 2019 Author Share Posted February 15, 2019 I think I put together a sample script correctly. Well almost because it isn't working yet. #include "CUIAutomation2.au3" Example() Func Example() ; Open Homeseer Run(@ComSpec & " /c " & """C:\Programs\HomeSeer HS3\HS3.exe"" ", "", @SW_HIDE) Sleep(1000) ; Create UI Automation object Local $oUIAutomation = ObjCreateInterface($sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation) If Not IsObj($oUIAutomation) Then Return ConsoleWrite("$oUIAutomation ERR" & @CRLF) ConsoleWrite("$oUIAutomation OK" & @CRLF) ; Get Desktop element Local $pDesktop, $oDesktop $oUIAutomation.GetRootElement($pDesktop) $oDesktop = ObjCreateInterface($pDesktop, $sIID_IUIAutomationElement, $dtagIUIAutomationElement) If Not IsObj($oDesktop) Then Return ConsoleWrite("$oDesktop ERR" & @CRLF) ConsoleWrite("$oDesktop OK" & @CRLF) ; --- Find window/control --- ConsoleWrite("--- Find window/control ---" & @CRLF) Local $pCondition0 $oUIAutomation.CreatePropertyCondition($UIA_ClassNamePropertyId, "WindowsForms10.BUTTON.app.0.141b42a_r14_ad1", $pCondition0) If Not $pCondition0 Then Return ConsoleWrite("$pCondition0 ERR" & @CRLF) ConsoleWrite("$pCondition0 OK" & @CRLF) Local $pPane, $oPane, $oParent $oParent.FindFirst($TreeScope_Descendants, $pCondition0, $pPane) $oPane = ObjCreateInterface($pPane, $sIID_IUIAutomationElement, $dtagIUIAutomationElement) If Not IsObj($oPane) Then Return ConsoleWrite("$oPane ERR" & @CRLF) ConsoleWrite("$oPane OK" & @CRLF) EndFunc ;==>Example In the console I am getting: $oUIAutomation OK $oDesktop OK --- Find window/control --- $pCondition0 OK "C:\Dnload\HomeSeer HS3 Pro\ClickRegisterNowButton.au3" (32) : ==> Variable must be of type "Object".: $oParent.FindFirst($TreeScope_Descendants, $pCondition0, $pPane) $oParent^ ERROR I have no idea how to fix this. Link to comment Share on other sites More sharing options...
LarsJ Posted February 15, 2019 Share Posted February 15, 2019 You must identify the top window "HomeSeer HS3" before you identify the pane control. Then replace $oParent with the top window. Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
Docfxit Posted February 16, 2019 Author Share Posted February 16, 2019 4 hours ago, LarsJ said: You must identify the top window "HomeSeer HS3" before you identify the pane control. Then replace $oParent with the top window. I don't know how to do that. Could someone please help me with this? Thanks, Docfxit Link to comment Share on other sites More sharing options...
LarsJ Posted February 16, 2019 Share Posted February 16, 2019 I've installed "HomeSeer HS3" on my Windows 7 PC. 0000 Window: HomeSeer HS3 0001 Text: Get FREE Trial License 0002 Hyperlink: Get FREE Trial License 0003 Text: Version 3.0.0.500 0004 Text: Please Register to Use or 0005 Text: ----- 0006 Text: ----- 0007 Button: Upgrade to PRO 0008 Button: Register Now... 0009 Button: Continue Trial 0010 Text: Errors/Warnings: 0011 Button: Web Interface 0012 Button: Startup Log 0013 Edit: WindowsForms10.EDIT.app.0.141b42a_r14_ad1 0014 ScrollBar: Vertical 0015 Button: Line up 0016 Button: Line down 0017 Pane: WindowsForms10.Window.8.app.0.141b42a_r14_ad1 0018 ProgressBar: WindowsForms10.msctls_progress32.app.0.141b42a_r14_ad1 0019 TitleBar 0020 MenuBar: System 0021 MenuItem: System 0022 Button: Minimize 0023 Button: Maximize 0024 Button: Close The application does not contain quite a lot of automation code. The only code that works is: expandcollapse popup#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ;#AutoIt3Wrapper_UseX64=n ; If target application is running as 32 bit code ;#AutoIt3Wrapper_UseX64=y ; If target application is running as 64 bit code #include "CUIAutomation2.au3" Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Open HomeSeer Run( "C:\Program Files (x86)\HomeSeer HS3\HS3.exe" ) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Sleep( 1000 ) ; Create UI Automation object Local $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation ) If Not IsObj( $oUIAutomation ) Then Return ConsoleWrite( "$oUIAutomation ERR" & @CRLF ) ConsoleWrite( "$oUIAutomation OK" & @CRLF ) ; Get Desktop element Local $pDesktop, $oDesktop $oUIAutomation.GetRootElement( $pDesktop ) $oDesktop = ObjCreateInterface( $pDesktop, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oDesktop ) Then Return ConsoleWrite( "$oDesktop ERR" & @CRLF ) ConsoleWrite( "$oDesktop OK" & @CRLF ) ; --- Find window/control --- ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pCondition1 $oUIAutomation.CreateTrueCondition( $pCondition1 ) If Not $pCondition1 Then Return ConsoleWrite( "$pCondition1 ERR" & @CRLF ) ConsoleWrite( "$pCondition1 OK" & @CRLF ) Local $pElements $oDesktop.FindAll( $TreeScope_Descendants, $pCondition1, $pElements ) If Not $pElements Then Return ConsoleWrite( "$pElements ERR" & @CRLF ) ConsoleWrite( "$pElements OK" & @CRLF ) Local $oAutomationElementArray, $iLength $oAutomationElementArray = ObjCreateInterFace( $pElements, $sIID_IUIAutomationElementArray, $dtagIUIAutomationElementArray ) $oAutomationElementArray.Length( $iLength ) If Not $iLength Then Return ConsoleWrite( "$iLength ERR" & @CRLF ) ConsoleWrite( "$iLength OK" & @CRLF ) Local $pUIElement, $oUIElement, $sName For $i = 0 To $iLength - 1 $oAutomationElementArray.GetElement( $i, $pUIElement ) $oUIElement = ObjCreateInterface( $pUIElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) $oUIElement.GetCurrentPropertyValue( $UIA_NamePropertyId, $sName ) If $sName <> "HomeSeer HS3" Then ContinueLoop ConsoleWrite( "$sName = " & $sName & @CRLF ) For $j = $i + 1 To $iLength - 1 $oAutomationElementArray.GetElement( $j, $pUIElement ) $oUIElement = ObjCreateInterface( $pUIElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) $oUIElement.GetCurrentPropertyValue( $UIA_NamePropertyId, $sName ) If $sName <> "Register Now..." Then ContinueLoop ConsoleWrite( "$sName = " & $sName & @CRLF ) ConsoleWrite( "$oControl OK" & @CRLF ) ExitLoop 2 Next Next ; --- Invoke Pattern (action) Object --- ConsoleWrite( "--- Invoke Pattern (action) Object ---" & @CRLF ) Local $pInvokePattern, $oInvokePattern $oUIElement.GetCurrentPattern( $UIA_InvokePatternId, $pInvokePattern ) $oInvokePattern = ObjCreateInterface( $pInvokePattern, $sIID_IUIAutomationInvokePattern, $dtagIUIAutomationInvokePattern ) If Not IsObj( $oInvokePattern ) Then Return ConsoleWrite( "$oInvokePattern ERR" & @CRLF ) ConsoleWrite( "$oInvokePattern OK" & @CRLF ) ; --- Invoke Pattern (action) Methods --- ConsoleWrite( "--- Invoke Pattern (action) Methods ---" & @CRLF ) ConsoleWrite( "$oInvokePattern.Invoke()" & @CRLF ) $oInvokePattern.Invoke() EndFunc $oUIAutomation OK $oDesktop OK --- Find window/control --- $pCondition1 OK $pElements OK $iLength OK $sName = HomeSeer HS3 $sName = Register Now... $oControl OK --- Invoke Pattern (action) Object --- $oInvokePattern OK --- Invoke Pattern (action) Methods --- $oInvokePattern.Invoke() Advanced techniques like the FindAll() method have not yet been addressed in the automation threads. They'll be reviewed in a new update in a month. There'll be a major update next weekend with improved sample code generation. Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
LarsJ Posted February 16, 2019 Share Posted February 16, 2019 I've figured it out. You have to be very careful to find the top window directly from the Desktop in this way: ; --- Find HomeSeer HS3 window --- ConsoleWrite( "--- Find HomeSeer HS3 window ---" & @CRLF ) Local $pCondition0 $oUIAutomation.CreateTrueCondition( $pCondition0 ) If Not $pCondition0 Then Return ConsoleWrite( "$pCondition0 ERR" & @CRLF ) ConsoleWrite( "$pCondition0 OK" & @CRLF ) Local $pElements $oDesktop.FindAll( $TreeScope_Children, $pCondition0, $pElements ) ; Top windows only If Not $pElements Then Return ConsoleWrite( "$pElements ERR" & @CRLF ) ConsoleWrite( "$pElements OK" & @CRLF ) Local $oAutomationElementArray, $iLength $oAutomationElementArray = ObjCreateInterFace( $pElements, $sIID_IUIAutomationElementArray, $dtagIUIAutomationElementArray ) $oAutomationElementArray.Length( $iLength ) If Not $iLength Then Return ConsoleWrite( "$iLength ERR" & @CRLF ) ConsoleWrite( "$iLength = " & $iLength & @CRLF ) ConsoleWrite( "$iLength OK" & @CRLF ) Local $pWindow, $oWindow, $sName For $i = 0 To $iLength - 1 $oAutomationElementArray.GetElement( $i, $pWindow ) $oWindow = ObjCreateInterface( $pWindow, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) $oWindow.GetCurrentPropertyValue( $UIA_NamePropertyId, $sName ) If $sName <> "HomeSeer HS3" Then ContinueLoop ConsoleWrite( "$sName = " & $sName & @CRLF ) ExitLoop Next If $i = $iLength Then Return ConsoleWrite( "$oWindow ERR" & @CRLF ) ConsoleWrite( "$oWindow OK" & @CRLF ) This technique will be included in the next version of UIASpy in a week. Full code: expandcollapse popup#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ;#AutoIt3Wrapper_UseX64=n ; If target application is running as 32 bit code ;#AutoIt3Wrapper_UseX64=y ; If target application is running as 64 bit code #include "CUIAutomation2.au3" Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Open HomeSeer Run( "C:\Program Files (x86)\HomeSeer HS3\HS3.exe" ) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Sleep( 1000 ) ; Create UI Automation object Local $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation ) If Not IsObj( $oUIAutomation ) Then Return ConsoleWrite( "$oUIAutomation ERR" & @CRLF ) ConsoleWrite( "$oUIAutomation OK" & @CRLF ) ; Get Desktop element Local $pDesktop, $oDesktop $oUIAutomation.GetRootElement( $pDesktop ) $oDesktop = ObjCreateInterface( $pDesktop, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oDesktop ) Then Return ConsoleWrite( "$oDesktop ERR" & @CRLF ) ConsoleWrite( "$oDesktop OK" & @CRLF ) ; --- Find HomeSeer HS3 window --- ConsoleWrite( "--- Find HomeSeer HS3 window ---" & @CRLF ) Local $pCondition0 $oUIAutomation.CreateTrueCondition( $pCondition0 ) If Not $pCondition0 Then Return ConsoleWrite( "$pCondition0 ERR" & @CRLF ) ConsoleWrite( "$pCondition0 OK" & @CRLF ) Local $pElements $oDesktop.FindAll( $TreeScope_Children, $pCondition0, $pElements ) ; Top windows only If Not $pElements Then Return ConsoleWrite( "$pElements ERR" & @CRLF ) ConsoleWrite( "$pElements OK" & @CRLF ) Local $oAutomationElementArray, $iLength $oAutomationElementArray = ObjCreateInterFace( $pElements, $sIID_IUIAutomationElementArray, $dtagIUIAutomationElementArray ) $oAutomationElementArray.Length( $iLength ) If Not $iLength Then Return ConsoleWrite( "$iLength ERR" & @CRLF ) ConsoleWrite( "$iLength = " & $iLength & @CRLF ) ConsoleWrite( "$iLength OK" & @CRLF ) Local $pWindow, $oWindow, $sName For $i = 0 To $iLength - 1 $oAutomationElementArray.GetElement( $i, $pWindow ) $oWindow = ObjCreateInterface( $pWindow, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) $oWindow.GetCurrentPropertyValue( $UIA_NamePropertyId, $sName ) If $sName <> "HomeSeer HS3" Then ContinueLoop ConsoleWrite( "$sName = " & $sName & @CRLF ) ExitLoop Next If $i = $iLength Then Return ConsoleWrite( "$oWindow ERR" & @CRLF ) ConsoleWrite( "$oWindow OK" & @CRLF ) ; --- Find Register Now... button --- ConsoleWrite( "--- Find Register Now... button ---" & @CRLF ) Local $pCondition1 $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "Register Now...", $pCondition1 ) If Not $pCondition1 Then Return ConsoleWrite( "$pCondition1 ERR" & @CRLF ) ConsoleWrite( "$pCondition1 OK" & @CRLF ) Local $pButton1, $oButton1 $oWindow.FindFirst( $TreeScope_Descendants, $pCondition1, $pButton1 ) $oButton1 = ObjCreateInterface( $pButton1, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oButton1 ) Then Return ConsoleWrite( "$oButton1 ERR" & @CRLF ) ConsoleWrite( "$oButton1 OK" & @CRLF ) ; --- Invoke Pattern (action) Object --- ConsoleWrite( "--- Invoke Pattern (action) Object ---" & @CRLF ) Local $pInvokePattern, $oInvokePattern $oButton1.GetCurrentPattern( $UIA_InvokePatternId, $pInvokePattern ) $oInvokePattern = ObjCreateInterface( $pInvokePattern, $sIID_IUIAutomationInvokePattern, $dtagIUIAutomationInvokePattern ) If Not IsObj( $oInvokePattern ) Then Return ConsoleWrite( "$oInvokePattern ERR" & @CRLF ) ConsoleWrite( "$oInvokePattern OK" & @CRLF ) ; --- Invoke Pattern (action) Methods --- ConsoleWrite( "--- Invoke Pattern (action) Methods ---" & @CRLF ) ConsoleWrite( "$oInvokePattern.Invoke()" & @CRLF ) $oInvokePattern.Invoke() EndFunc $oUIAutomation OK $oDesktop OK --- Find HomeSeer HS3 window --- $pCondition0 OK $pElements OK $iLength = 8 $iLength OK $sName = HomeSeer HS3 $oWindow OK --- Find Register Now... button --- $pCondition1 OK $oButton1 OK --- Invoke Pattern (action) Object --- $oInvokePattern OK --- Invoke Pattern (action) Methods --- $oInvokePattern.Invoke() Docfxit and Earthshine 1 1 Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
Docfxit Posted February 16, 2019 Author Share Posted February 16, 2019 That is super nice of you to download, install and figure out all the code required to get it running. I can't thank you enough. :-) I tried running the script. I'm getting an error. I have the script in SciTe. The file CUIAutomation2.au3 opened up in SciTe with the error: Is there something I'm doing wrong? Thanks, Docfxit Link to comment Share on other sites More sharing options...
LarsJ Posted February 16, 2019 Share Posted February 16, 2019 I've made that kind of code a million times. And I'll just reinstall my C-drive image. You had some running code yesterday with console output. A handful of posts above. You already know how to do it. Note that I made the code on Windows 7. I think you are on Windows 10. I can see that the UIASpy info is different. Your controls are pane controls. Mine are buttons. Don't be too disappointed if it doesn't work. I'll test the code on Windows 10. And post the code. But it won't be until tomorrow. Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
Docfxit Posted February 17, 2019 Author Share Posted February 17, 2019 (edited) I'm running it in Win7 64bit. I don't understand why you see buttons unless you have a different version. I tried to run it. I had to add these lines to make it run: Global $sCLSID_UIAutomationClient Global $UIA_InvokePatternId ; Line 834 in CUIAutomation2.au3 was changed ; From Local $UIA_propertiesSupportedArray[115][2] = [ _ ; To Global $UIA_propertiesSupportedArray[115][2] = [ _ ; Because of Warning Local specifier in Global scope ; Line 953 in CUIAutomation2.au3 was changed ; From Local $UIA_ControlArray[41][3] = [ ; To Global $UIA_ControlArray[41][3] = [ ; Because of Warning Local specifier in Global scope When I ran it I received this error in the console: $pCondition0 OK $pElements OK $iLength = 6 $iLength OK $oWindow ERR Thank you very much for helping me with this, Docfxit Edited February 17, 2019 by Docfxit Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now