Created
December 20, 2017 21:50
-
-
Save atimermann/da1f8b6d1c326341cb9ec696012a57c3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#cs ---------------------------------------------------------------------------- | |
AutoIt Version: 3.3.12.0 | |
Author: André Timermann | |
Script Function: | |
Manipulador de Objeto Avançado | |
NOTA: Estou desenvolvendo uma biblioteca mais completa com interface gráfica, no futuro será migrado | |
Ferramentas: | |
_ObjectManager_ListChildren(OBJETO) | |
- Listar todos os objetos Diponíveis, indexando-os | |
- Se nenhum parâmetro for passado busca no nível mais alto (DESKTOP) | |
_ObjectManager_ShowProperty(INDEX, OBJETO) | |
- Retorna propriedades completa de um Objeto, deve ser passado o indice e o objeto pai | |
- NULL no OBJETO representa OBJETO PAI DE TODOS(DESKTOP) | |
_ObjectManager_getObject(DESC OBJ) | |
- Crie uma forma mais simples de descrever um objeto, através de um array hierarquico de | |
- Esse Array é salvo num arquivo separado | |
- Podemos recuperar o Objeto através desta função | |
- Se não encontrar Retorna null | |
#ce ---------------------------------------------------------------------------- | |
#include-once | |
#include "../vendor/UIAWrappers.au3" | |
#include <array.au3> | |
#AutoIt3Wrapper_UseX64=Y | |
; Array de Propriedades porém ordenado por importancia | |
Local $ObjectManager_propertiesSupportedArrayImportant[123][2] = [ _ | |
["indexrelative", -1], _ ; Special propertyname | |
["index", -1], _ ; Special propertyname | |
["instance", -1], _ ; Special propertyname | |
["title", $UIA_NamePropertyId], _ ; Alternate propertyname | |
["class", $UIA_ClassNamePropertyId], _ ; Alternate propertyname | |
["ControlType", $UIA_ControlTypePropertyId], _ | |
["id", $UIA_AutomationIdPropertyId], _ ; Alternate propertyname | |
["ProcessId", $UIA_ProcessIdPropertyId], _ | |
["ControllerFor", $UIA_ControllerForPropertyId], _ | |
["RuntimeId", $UIA_RuntimeIdPropertyId], _ | |
["BoundingRectangle", $UIA_BoundingRectanglePropertyId], _ | |
["IsKeyboardFocusable", $UIA_IsKeyboardFocusablePropertyId], _ | |
["handle", $UIA_NativeWindowHandlePropertyId], _ ; Alternate propertyname | |
["text", $UIA_NamePropertyId], _ ; Alternate propertyname | |
["regexptitle", $UIA_NamePropertyId], _ ; Alternate propertyname | |
["regexpclass", $UIA_ClassNamePropertyId], _ ; Alternate propertyname | |
["iaccessiblevalue", $UIA_LegacyIAccessibleValuePropertyId], _ ; Alternate propertyname | |
["iaccessiblechildId", $UIA_LegacyIAccessibleChildIdPropertyId], _ ; Alternate propertyname | |
["LocalizedControlType", $UIA_LocalizedControlTypePropertyId], _ | |
["Name", $UIA_NamePropertyId], _ | |
["AcceleratorKey", $UIA_AcceleratorKeyPropertyId], _ | |
["AccessKey", $UIA_AccessKeyPropertyId], _ | |
["HasKeyboardFocus", $UIA_HasKeyboardFocusPropertyId], _ | |
["IsEnabled", $UIA_IsEnabledPropertyId], _ | |
["AutomationId", $UIA_AutomationIdPropertyId], _ | |
["ClassName", $UIA_ClassNamePropertyId], _ | |
["HelpText", $UIA_HelpTextPropertyId], _ | |
["ClickablePoint", $UIA_ClickablePointPropertyId], _ | |
["Culture", $UIA_CulturePropertyId], _ | |
["IsControlElement", $UIA_IsControlElementPropertyId], _ | |
["IsContentElement", $UIA_IsContentElementPropertyId], _ | |
["LabeledBy", $UIA_LabeledByPropertyId], _ | |
["IsPassword", $UIA_IsPasswordPropertyId], _ | |
["NativeWindowHandle", $UIA_NativeWindowHandlePropertyId], _ | |
["ItemType", $UIA_ItemTypePropertyId], _ | |
["IsOffscreen", $UIA_IsOffscreenPropertyId], _ | |
["Orientation", $UIA_OrientationPropertyId], _ | |
["FrameworkId", $UIA_FrameworkIdPropertyId], _ | |
["IsRequiredForForm", $UIA_IsRequiredForFormPropertyId], _ | |
["ItemStatus", $UIA_ItemStatusPropertyId], _ | |
["IsDockPatternAvailable", $UIA_IsDockPatternAvailablePropertyId], _ | |
["IsExpandCollapsePatternAvailable", $UIA_IsExpandCollapsePatternAvailablePropertyId], _ | |
["IsGridItemPatternAvailable", $UIA_IsGridItemPatternAvailablePropertyId], _ | |
["IsGridPatternAvailable", $UIA_IsGridPatternAvailablePropertyId], _ | |
["IsInvokePatternAvailable", $UIA_IsInvokePatternAvailablePropertyId], _ | |
["IsMultipleViewPatternAvailable", $UIA_IsMultipleViewPatternAvailablePropertyId], _ | |
["IsRangeValuePatternAvailable", $UIA_IsRangeValuePatternAvailablePropertyId], _ | |
["IsScrollPatternAvailable", $UIA_IsScrollPatternAvailablePropertyId], _ | |
["IsScrollItemPatternAvailable", $UIA_IsScrollItemPatternAvailablePropertyId], _ | |
["IsSelectionItemPatternAvailable", $UIA_IsSelectionItemPatternAvailablePropertyId], _ | |
["IsSelectionPatternAvailable", $UIA_IsSelectionPatternAvailablePropertyId], _ | |
["IsTablePatternAvailable", $UIA_IsTablePatternAvailablePropertyId], _ | |
["IsTableItemPatternAvailable", $UIA_IsTableItemPatternAvailablePropertyId], _ | |
["IsTextPatternAvailable", $UIA_IsTextPatternAvailablePropertyId], _ | |
["IsTogglePatternAvailable", $UIA_IsTogglePatternAvailablePropertyId], _ | |
["IsTransformPatternAvailable", $UIA_IsTransformPatternAvailablePropertyId], _ | |
["IsValuePatternAvailable", $UIA_IsValuePatternAvailablePropertyId], _ | |
["IsWindowPatternAvailable", $UIA_IsWindowPatternAvailablePropertyId], _ | |
["ValueValue", $UIA_ValueValuePropertyId], _ | |
["ValueIsReadOnly", $UIA_ValueIsReadOnlyPropertyId], _ | |
["RangeValueValue", $UIA_RangeValueValuePropertyId], _ | |
["RangeValueIsReadOnly", $UIA_RangeValueIsReadOnlyPropertyId], _ | |
["RangeValueMinimum", $UIA_RangeValueMinimumPropertyId], _ | |
["RangeValueMaximum", $UIA_RangeValueMaximumPropertyId], _ | |
["RangeValueLargeChange", $UIA_RangeValueLargeChangePropertyId], _ | |
["RangeValueSmallChange", $UIA_RangeValueSmallChangePropertyId], _ | |
["ScrollHorizontalScrollPercent", $UIA_ScrollHorizontalScrollPercentPropertyId], _ | |
["ScrollHorizontalViewSize", $UIA_ScrollHorizontalViewSizePropertyId], _ | |
["ScrollVerticalScrollPercent", $UIA_ScrollVerticalScrollPercentPropertyId], _ | |
["ScrollVerticalViewSize", $UIA_ScrollVerticalViewSizePropertyId], _ | |
["ScrollHorizontallyScrollable", $UIA_ScrollHorizontallyScrollablePropertyId], _ | |
["ScrollVerticallyScrollable", $UIA_ScrollVerticallyScrollablePropertyId], _ | |
["SelectionSelection", $UIA_SelectionSelectionPropertyId], _ | |
["SelectionCanSelectMultiple", $UIA_SelectionCanSelectMultiplePropertyId], _ | |
["SelectionIsSelectionRequired", $UIA_SelectionIsSelectionRequiredPropertyId], _ | |
["GridRowCount", $UIA_GridRowCountPropertyId], _ | |
["GridColumnCount", $UIA_GridColumnCountPropertyId], _ | |
["GridItemRow", $UIA_GridItemRowPropertyId], _ | |
["GridItemColumn", $UIA_GridItemColumnPropertyId], _ | |
["GridItemRowSpan", $UIA_GridItemRowSpanPropertyId], _ | |
["GridItemColumnSpan", $UIA_GridItemColumnSpanPropertyId], _ | |
["GridItemContainingGrid", $UIA_GridItemContainingGridPropertyId], _ | |
["DockDockPosition", $UIA_DockDockPositionPropertyId], _ | |
["ExpandCollapseExpandCollapseState", $UIA_ExpandCollapseExpandCollapseStatePropertyId], _ | |
["MultipleViewCurrentView", $UIA_MultipleViewCurrentViewPropertyId], _ | |
["MultipleViewSupportedViews", $UIA_MultipleViewSupportedViewsPropertyId], _ | |
["WindowCanMaximize", $UIA_WindowCanMaximizePropertyId], _ | |
["WindowCanMinimize", $UIA_WindowCanMinimizePropertyId], _ | |
["WindowWindowVisualState", $UIA_WindowWindowVisualStatePropertyId], _ | |
["WindowWindowInteractionState", $UIA_WindowWindowInteractionStatePropertyId], _ | |
["WindowIsModal", $UIA_WindowIsModalPropertyId], _ | |
["WindowIsTopmost", $UIA_WindowIsTopmostPropertyId], _ | |
["SelectionItemIsSelected", $UIA_SelectionItemIsSelectedPropertyId], _ | |
["SelectionItemSelectionContainer", $UIA_SelectionItemSelectionContainerPropertyId], _ | |
["TableRowHeaders", $UIA_TableRowHeadersPropertyId], _ | |
["TableColumnHeaders", $UIA_TableColumnHeadersPropertyId], _ | |
["TableRowOrColumnMajor", $UIA_TableRowOrColumnMajorPropertyId], _ | |
["TableItemRowHeaderItems", $UIA_TableItemRowHeaderItemsPropertyId], _ | |
["TableItemColumnHeaderItems", $UIA_TableItemColumnHeaderItemsPropertyId], _ | |
["ToggleToggleState", $UIA_ToggleToggleStatePropertyId], _ | |
["TransformCanMove", $UIA_TransformCanMovePropertyId], _ | |
["TransformCanResize", $UIA_TransformCanResizePropertyId], _ | |
["TransformCanRotate", $UIA_TransformCanRotatePropertyId], _ | |
["IsLegacyIAccessiblePatternAvailable", $UIA_IsLegacyIAccessiblePatternAvailablePropertyId], _ | |
["LegacyIAccessibleChildId", $UIA_LegacyIAccessibleChildIdPropertyId], _ | |
["LegacyIAccessibleName", $UIA_LegacyIAccessibleNamePropertyId], _ | |
["LegacyIAccessibleValue", $UIA_LegacyIAccessibleValuePropertyId], _ | |
["LegacyIAccessibleDescription", $UIA_LegacyIAccessibleDescriptionPropertyId], _ | |
["LegacyIAccessibleRole", $UIA_LegacyIAccessibleRolePropertyId], _ | |
["LegacyIAccessibleState", $UIA_LegacyIAccessibleStatePropertyId], _ | |
["LegacyIAccessibleHelp", $UIA_LegacyIAccessibleHelpPropertyId], _ | |
["LegacyIAccessibleKeyboardShortcut", $UIA_LegacyIAccessibleKeyboardShortcutPropertyId], _ | |
["LegacyIAccessibleSelection", $UIA_LegacyIAccessibleSelectionPropertyId], _ | |
["LegacyIAccessibleDefaultAction", $UIA_LegacyIAccessibleDefaultActionPropertyId], _ | |
["AriaRole", $UIA_AriaRolePropertyId], _ | |
["AriaProperties", $UIA_AriaPropertiesPropertyId], _ | |
["IsDataValidForForm", $UIA_IsDataValidForFormPropertyId], _ | |
["DescribedBy", $UIA_DescribedByPropertyId], _ | |
["FlowsTo", $UIA_FlowsToPropertyId], _ | |
["ProviderDescription", $UIA_ProviderDescriptionPropertyId], _ | |
["IsItemContainerPatternAvailable", $UIA_IsItemContainerPatternAvailablePropertyId], _ | |
["IsVirtualizedItemPatternAvailable", $UIA_IsVirtualizedItemPatternAvailablePropertyId], _ | |
["IsSynchronizedInputPatternAvailable", $UIA_IsSynchronizedInputPatternAvailablePropertyId] _ | |
] | |
;AutoItSetOption("MustDeclareVars", 1) | |
; #FUNCTION# ==================================================================================================================== | |
; Name ..........: _ObjectManager_ListChildren | |
; Description ...: Imprime/Retorna lista de Objetos Filhos e suas propriedades | |
; Syntax ........: _ObjectManager_ListChildren([, $oElement = $UIA_oDesktop [, $TreeScope = $TreeScope_Children]]) | |
; Parameters ....: $oElement - [optional] Elemento a ser analisado. Default is $UIA_oDesktop. | |
; $TreeScope - [optional] A dll struct value. Default is $TreeScope_Children. | |
; Return values .: None | |
; Author ........: André Timermann | |
; Modified ......: | |
; Remarks .......: | |
; Related .......: | |
; Link ..........: | |
; Example .......: No | |
; =============================================================================================================================== | |
Func _ObjectManager_ListChildren($oElement = $UIA_oDesktop, $TreeScope = $TreeScope_Children) | |
ConsoleWrite("Iniciando busca... " & @CRLF); | |
Local $iLength; | |
Local $oAutomationElementArray = __ObjectManager_GetElements($oElement, $TreeScope_Children) | |
If Not IsObj($oAutomationElementArray) Then | |
ConsoleWrite("Objeto Inválido" & @CRLF) | |
Return 0; | |
EndIf | |
$oAutomationElementArray.Length($iLength) | |
ConsoleWrite("Total Elementos Encontrados: " & $iLength & @CRLF); | |
For $i = 0 To $iLength - 1; it's zero based | |
$oAutomationElementArray.GetElement($i, $UIA_pUIElement) | |
$UIA_oUIElement = ObjCreateInterface($UIA_pUIElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement) | |
; Imprime #ID | |
ConsoleWrite("[" & $i & "] "); | |
$name = _UIA_getPropertyValue($UIA_oUIElement, $UIA_NamePropertyId) | |
$class = _UIA_getPropertyValue($UIA_oUIElement, $UIA_ClassNamePropertyId) | |
ConsoleWrite("Title:" & $name & " (ClassName:" & $class & ")" & @CRLF) | |
Next | |
ConsoleWrite(@CRLF) | |
EndFunc ;==>_ObjectManager_ListChildren | |
; #FUNCTION# ==================================================================================================================== | |
; Name ..........: _ObjectManager_ShowProperty | |
; Description ...: Retorna lista de propriedades de Elemento indexado pelo resultado de _ObjectManager_ListChildren | |
; Syntax ........: _ObjectManager_ShowProperty($index [, $oElement = $UIA_oDesktop [, $TreeScope = $TreeScope_Children]]) | |
; Parameters ....: $index - Indice do Componente | |
; $oElement - [optional] Elemento a ser analisado. Default is $UIA_oDesktop. | |
; $TreeScope - [optional] A dll struct value. Default is $TreeScope_Children. | |
; Return values .: None | |
; Author ........: André Timermann | |
; Modified ......: | |
; Remarks .......: | |
; Related .......: | |
; Link ..........: | |
; Example .......: No | |
; =============================================================================================================================== | |
Func _ObjectManager_ShowProperty($index, $oElement = $UIA_oDesktop, $TreeScope = $TreeScope_Children) | |
ConsoleWrite("Iniciando busca... " & @CRLF); | |
Local $iLength; | |
Local $oAutomationElementArray = __ObjectManager_GetElements($oElement, $TreeScope_Children) | |
If Not IsObj($oAutomationElementArray) Then | |
ConsoleWrite("Objeto Inválido" & @CRLF) | |
Return 0; | |
EndIf | |
$oAutomationElementArray.GetElement($index, $UIA_pUIElement) | |
$UIA_oUIElement = ObjCreateInterface($UIA_pUIElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement) | |
; ---------------------------------------------------------------------------------- | |
; Lê todas as propriedades: | |
; ---------------------------------------------------------------------------------- | |
For $i = 0 To UBound($ObjectManager_propertiesSupportedArrayImportant) - 1; | |
;Exclude the special ones | |
If $UIA_propertiesSupportedArray[$i][1] <> -1 Then | |
$tval = _UIA_getPropertyValue($UIA_oUIElement, $ObjectManager_propertiesSupportedArrayImportant[$i][1]) | |
;If $tval <> "" Then | |
$tKey = $ObjectManager_propertiesSupportedArrayImportant[$i][0]; | |
; ---------------------------------------------------------------------------------- | |
; ENUM | |
; ---------------------------------------------------------------------------------- | |
If $tKey == 'ControlType' Then | |
ConsoleWrite("[" & $i & "] " & $tKey & ":= <" & _UIA_getControlName(_UIA_getPropertyValue($UIA_oUIElement, $UIA_ControlTypePropertyId)) & ">, " _ | |
& "<" & _UIA_getPropertyValue($UIA_oUIElement, $UIA_ControlTypePropertyId) & ">, " _ | |
& "(" & Hex(_UIA_getPropertyValue($UIA_oUIElement, $UIA_ControlTypePropertyId)) & "), " & @CRLF) | |
; ---------------------------------------------------------------------------------- | |
; GENERICOS | |
; ---------------------------------------------------------------------------------- | |
Else | |
ConsoleWrite("[" & $i & "] " & $tKey & ":= <" & $tval & ">" & @CRLF) | |
EndIf | |
;EndIf | |
EndIf | |
Next | |
EndFunc ;==>_ObjectManager_getAllPropertyValues | |
#CS ---------------------------------------------------------------------------- | |
_ObjectManager_DumpObject | |
Imprime Arvore hierarquica de objetos relacionado | |
$oElementStart -> Objeto Alvo (Padrão é objeto Raiz $UIA_oDesktop que representa o Windows) | |
$flags -> Parâmetros que define como os objetos serão retornados | |
$tab -> Nível Hierarquivo para impressão (Uso interno) | |
#CE ---------------------------------------------------------------------------- | |
Func _ObjectManager_DumpObject($oElementStart = $UIA_oDesktop, $flags = 0, $tab = "", $dumpStr = "", $level = 0) | |
Local $pCondition, $pTrueCondition, $oCondition, $oAutomationElementArray | |
Local $pElements, $iLength, $i | |
Local $tStr | |
$oAutomationElementArray = __ObjectManager_GetElements($oElementStart, $TreeScope_Children) | |
If Not IsObj($oAutomationElementArray) Then | |
Return 0; | |
EndIf | |
$oAutomationElementArray.Length($iLength) | |
;If $iLength = 0 Then | |
;Return "Nenhum Registro Encontrado" & @CRLF; | |
;EndIf | |
; ---------------------------------------------------------------------------------------- | |
; Inicia Busca | |
; ---------------------------------------------------------------------------------------- | |
$dumpStr = $dumpStr & $tab & $iLength & @CRLF; | |
ConsoleWrite($dumpStr & @LF); | |
Sleep(2000); | |
Local $name, $class; | |
For $i = 0 To $iLength - 1; it's zero based | |
Sleep(1000); | |
$oAutomationElementArray.GetElement($i, $UIA_pUIElement) | |
$UIA_oUIElement = ObjCreateInterface($UIA_pUIElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement) | |
;$dumpStr=$dumpStr & $tab & "-----------------------------------------------------------------------------------------------" & @CRLF; | |
$dumpStr = $dumpStr & $tab & "Elemento " & $i & @CRLF; | |
;$dumpStr=$dumpStr & $tab & "-----------------------------------------------------------------------------------------------" & @CRLF; | |
;$dumpStr = $dumpStr & _ObjectManager_getAllPropertyValues($UIA_oUIElement, 10, $tab); | |
$name = _UIA_getPropertyValue($UIA_oUIElement, $UIA_NamePropertyId) | |
$class = _UIA_getPropertyValue($UIA_oUIElement, $UIA_ClassNamePropertyId) | |
$dumpStr = $dumpStr & $tab & '<' & $name & '>(<' & $class & '>)' & @CRLF; | |
;if $level <= 3 Then | |
;$dumpStr = $dumpStr & _ObjectManager_DumpObject($UIA_oUIElement, $flags, $tab & @TAB, $dumpStr, $level + 1) | |
;EndIf | |
Next | |
Return $dumpStr | |
EndFunc ;==>_ObjectManager_DumpObject | |
#CS ---------------------------------------------------------------------------- | |
_ObjectManager_ListPropertyObject | |
Imprime todas as propriedades relevantes do objeto especificado por $oElementStart de acordo com $TreeScope | |
$oElementStart -> Objeto Alvo (Padrão é objeto Raiz $UIA_oDesktop que representa o Windows) | |
$TreeScope -> Método de Busca | |
$importance -> Quantidade de elementos retornado em ordem de importancia | |
#CE ---------------------------------------------------------------------------- | |
Func _ObjectManager_ListPropertyObject($oElementStart = $UIA_oDesktop, $TreeScope = $TreeScope_Children, $importance = 10, $tab = "") | |
Local $pCondition, $pTrueCondition, $oCondition, $oAutomationElementArray | |
Local $pElements, $iLength, $i | |
Local $tStr | |
Local $dumpStr | |
; ---------------------------------------------------------------------------------------- | |
; Recupera Elementos | |
; ---------------------------------------------------------------------------------------- | |
$oAutomationElementArray = __ObjectManager_GetElements($oElementStart, $TreeScope) | |
If Not IsObj($oAutomationElementArray) Then | |
Return 0; | |
EndIf | |
$oAutomationElementArray.Length($iLength) | |
; If $iLength == 0 Then | |
;Return 0; | |
;EndIf | |
; ---------------------------------------------------------------------------------------- | |
; Inicia Busca | |
; ---------------------------------------------------------------------------------------- | |
$dumpStr = $dumpStr & $tab & "Elementos: " & $iLength & @CRLF; | |
Local $name, $class; | |
For $i = 0 To $iLength - 1; it's zero based | |
$oAutomationElementArray.GetElement($i, $UIA_pUIElement) | |
$UIA_oUIElement = ObjCreateInterface($UIA_pUIElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement) | |
$dumpStr = $dumpStr & $tab & "-----------------------------------------------------------------------------------------------" & @CRLF; | |
$dumpStr = $dumpStr & $tab & "Elemento " & $i & @CRLF; | |
$dumpStr = $dumpStr & $tab & "-----------------------------------------------------------------------------------------------" & @CRLF; | |
$dumpStr = $dumpStr & _ObjectManager_getAllPropertyValues($UIA_oUIElement, $importance, $tab); | |
Next | |
Return $dumpStr | |
EndFunc ;==>_ObjectManager_ListPropertyObject | |
#CS ---------------------------------------------------------------------------- | |
_ObjectManager_getAllPropertyValues | |
Retorna propriedade de objetos ordenado por importancia | |
$oElementStart -> Objeto Alvo (Padrão é objeto Raiz $UIA_oDesktop que representa o Windows) | |
$TreeScope -> Método de Busca | |
$importance -> Quantidade de elementos retornado em ordem de importancia | |
#CE ---------------------------------------------------------------------------- | |
Func _ObjectManager_getAllPropertyValues($UIA_oUIElement, $importance = -1, $tab = "") | |
Local $tStr, $tval, $tSeparator, $tKey; | |
$tStr = "" | |
$tSeparator = @CRLF ; To make sure its not a value you normally will get back for values | |
If $importance == -1 Then | |
$importance = UBound($ObjectManager_propertiesSupportedArrayImportant) - 1; | |
Else | |
$importance = $importance - 1 | |
EndIf | |
For $i = 0 To $importance | |
;~ Exclude the special ones | |
If $UIA_propertiesSupportedArray[$i][1] <> -1 Then | |
$tval = _UIA_getPropertyValue($UIA_oUIElement, $ObjectManager_propertiesSupportedArrayImportant[$i][1]) | |
;If $tval <> "" Then | |
$tKey = $ObjectManager_propertiesSupportedArrayImportant[$i][0]; | |
; ---------------------------------------------------------------------------------- | |
; ENUM | |
; ---------------------------------------------------------------------------------- | |
If $tKey == 'ControlType' Then | |
$tStr = $tStr & $tab & @TAB & $tKey & ":= <" & _UIA_getControlName(_UIA_getPropertyValue($UIA_oUIElement, $UIA_ControlTypePropertyId)) & ">, " _ | |
& "<" & _UIA_getPropertyValue($UIA_oUIElement, $UIA_ControlTypePropertyId) & ">, " _ | |
& "(" & Hex(_UIA_getPropertyValue($UIA_oUIElement, $UIA_ControlTypePropertyId)) & "), " _ | |
& $tSeparator | |
; ---------------------------------------------------------------------------------- | |
; GENERICOS | |
; ---------------------------------------------------------------------------------- | |
Else | |
$tStr = $tStr & $tab & @TAB & $tKey & ":= <" & $tval & ">" & $tSeparator | |
EndIf | |
;EndIf | |
EndIf | |
Next | |
Return $tStr | |
EndFunc ;==>_ObjectManager_getAllPropertyValues | |
#CS ---------------------------------------------------------------------------- | |
_ObjectManager_SearchObject | |
Busca Por um Objeto através de todas as suas propriedades | |
$searchTerm -> Termo de Busca | |
$oElementStart -> Objeto Alvo (Padrão é objeto Raiz $UIA_oDesktop que representa o Windows) | |
$TreeScope -> Método de Busca Padrão Todos os descendentes | |
#CE ---------------------------------------------------------------------------- | |
Func _ObjectManager_SearchObject($searchTerm, $oElementStart = $UIA_oDesktop, $TreeScope = $TreeScope_Descendants) | |
Local $oAutomationElementArray | |
Local $iLength | |
Local $tval, $tKey | |
Local $found, $foundList, $percent, $oldPercent; | |
$oAutomationElementArray = __ObjectManager_GetElements($oElementStart, $TreeScope) | |
If Not IsObj($oAutomationElementArray) Then | |
Return 0; | |
EndIf | |
$oAutomationElementArray.Length($iLength) | |
; Itera Por todos os Elementos | |
For $i = 0 To $iLength - 1; it's zero based | |
$oAutomationElementArray.GetElement($i, $UIA_pUIElement) | |
$UIA_oUIElement = ObjCreateInterface($UIA_pUIElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement) | |
; Imprime Progresso | |
$percent = Round(($i + 1) * 100 / $iLength, 0); | |
If $percent <> $oldPercent Then | |
$oldPercent = $percent | |
ConsoleWrite($percent & "%" & @CRLF); | |
EndIf | |
; Itera Por todas as Propriedades | |
$found = False; | |
$foundList = ''; | |
For $j = 0 To UBound($ObjectManager_propertiesSupportedArrayImportant) - 1; | |
; Ignora Propriedades Especiais | |
If $UIA_propertiesSupportedArray[$j][1] <> -1 Then | |
$tKey = $ObjectManager_propertiesSupportedArrayImportant[$j][0]; | |
$tval = _UIA_getPropertyValue($UIA_oUIElement, $ObjectManager_propertiesSupportedArrayImportant[$j][1]) | |
If $tval <> "" Then | |
;ConsoleWrite("Buscando " & $searchTerm & ": " & $tkey & " := " & $tval & @CRLF); | |
If (StringInStr($tval, $searchTerm) <> 0) Then | |
$found = True; | |
$foundList = $foundList & $tKey & " := " & $tval & @CRLF; | |
EndIf | |
EndIf | |
EndIf | |
Next | |
; Se Encontrou | |
If $found Then | |
ConsoleWrite("===============================================================================================" & @CRLF); | |
ConsoleWrite("Encontrado em " & $i & @CRLF); | |
ConsoleWrite($foundList); | |
ConsoleWrite("===============================================================================================" & @CRLF); | |
; Imprime Parentes | |
ConsoleWrite(_ObjectManager_ListPropertyObject($UIA_oUIElement, $TreeScope_Element, -1)) | |
; Não funciona | |
;ConsoleWrite (_ObjectManager_ListPropertyObject($UIA_oUIElement, $TreeScope_Parent, -1)) | |
EndIf | |
Next | |
EndFunc ;==>_ObjectManager_SearchObject | |
#CS ---------------------------------------------------------------------------- | |
__ObjectManager_GetElements (PRIVATED) | |
Retorna Elementos | |
$searchTerm -> Termo de Busca | |
$oElementStart -> Objeto Alvo (Padrão é objeto Raiz $UIA_oDesktop que representa o Windows) | |
$TreeScope -> Método de Busca | |
#CE ---------------------------------------------------------------------------- | |
Func __ObjectManager_GetElements($oElementStart = $UIA_oDesktop, $TreeScope = $TreeScope_Children) | |
Local $oAutomationElementArray, $pElements | |
$oElementStart.FindAll($TreeScope, $UIA_oTRUECondition, $pElements) | |
$oAutomationElementArray = ObjCreateInterface($pElements, $sIID_IUIAutomationElementArray, $dtagIUIAutomationElementArray) | |
If _UIA_IsElement($oAutomationElementArray) Then | |
Return $oAutomationElementArray | |
Else | |
Return 0; | |
EndIf | |
EndFunc ;==>__ObjectManager_GetElements | |
; #FUNCTION# ==================================================================================================================== | |
; Name ..........: __ObjectManager_getObject | |
; Description ...: Retorna um Objeto representando o Componente , se não encontrar retorna false | |
; Syntax ........: __ObjectManager_getObject($objectArray) | |
; Parameters ....: $objectArray - Descrição do Objeto em formato de Array, deve ser um array com a descrição de todos os objetos hierarquicamente | |
; Return values .: False se não Existe, Ponteiro se Existe. Use: isPtr para verificar | |
; Author ........: André Timermann | |
; Modified ......: | |
; Remarks .......: | |
; Related .......: | |
; Link ..........: | |
; Example .......: No | |
; =============================================================================================================================== | |
Func _ObjectManager_getObject($objectArray, $debug = false) | |
; Objeto Componente | |
Local $oElement = $UIA_oDesktop; | |
; Percorre todas as propriedades | |
For $vElement In $objectArray | |
$newElement = _UIA_getObjectByFindAll($oElement, $vElement, $TreeScope_Children); | |
; Verifica se é um objeto (existe) | |
if Not IsObj($newElement) Then | |
if $debug Then | |
ConsoleWrite("Elemento '" & $vElement & "' não encontrado! Opções:" & @CRLF) | |
_ObjectManager_ListChildren($oElement) | |
EndIf | |
return false; | |
EndIf | |
if $debug Then | |
ConsoleWrite("Elemento '" & $vElement & "' encontrado!" & @CRLF) | |
EndIf | |
$oElement = $newElement | |
Next | |
; Percorreu todas as propriedades (existe) | |
return $oElement; | |
EndFunc | |
; =========================================================================================== | |
; EXEMPLO DESCRIÇÃO DE UM OBJETO | |
; =========================================================================================== | |
;~ Local $operacaoSucessoDesc[7]; | |
;~ $operacaoSucessoDesc[0] = "Title:=Siscomex Carga - Windows Internet Explorer;controltype:=UIA_WindowControlTypeId;class:=IEFrame"; | |
;~ $operacaoSucessoDesc[1] = "controltype:=UIA_PaneControlTypeId;class:=Frame Tab"; | |
;~ $operacaoSucessoDesc[2] = "title:=Siscomex Carga - Windows Internet Explorer;controltype:=UIA_PaneControlTypeId;class:=TabWindowClass"; | |
;~ $operacaoSucessoDesc[3] = "controltype:=UIA_PaneControlTypeId;class:=Shell DocObject View"; | |
;~ $operacaoSucessoDesc[4] = "controltype:=UIA_PaneControlTypeId;class:=Internet Explorer_Server"; | |
;~ $operacaoSucessoDesc[5] = "title:=Siscomex Carga;controltype:=UIA_PaneControlTypeId"; | |
;~ $operacaoSucessoDesc[6] = "title:=Operação realizada com sucesso.;controltype:=UIA_TextControlTypeId"; | |
;~ $operacaoSucesso = __ObjectManager_getObject($operacaoSucessoDesc); | |
;~ if IsObj($operacaoSucesso) Then | |
;~ MsgBox(0, Default, "OK, OBJETO EXISTE") | |
;~ EndIf | |
; =========================================================================================== | |
; EXEMPLO DE COMO BUSCAR UM OBJETO, pode ser usado o SPY tb | |
; =========================================================================================== | |
;~ Local $oP0 = _UIA_getObjectByFindAll($UIA_oDesktop, "Title:=Siscomex Carga - Windows Internet Explorer;controltype:=UIA_WindowControlTypeId;class:=IEFrame", $TreeScope_Children); | |
;~ Local $oP1 = _UIA_getObjectByFindAll($oP0, "controltype:=UIA_PaneControlTypeId;class:=Frame Tab", $TreeScope_Children); | |
;~ Local $oP2 = _UIA_getObjectByFindAll($oP1, "title:=Siscomex Carga - Windows Internet Explorer;controltype:=UIA_PaneControlTypeId;class:=TabWindowClass", $TreeScope_Children); | |
;~ Local $oP3 = _UIA_getObjectByFindAll($oP2, "controltype:=UIA_PaneControlTypeId;class:=Shell DocObject View", $TreeScope_Children); | |
;~ Local $oP4 = _UIA_getObjectByFindAll($oP3, "controltype:=UIA_PaneControlTypeId;class:=Internet Explorer_Server", $TreeScope_Children); | |
;~ Local $oP5 = _UIA_getObjectByFindAll($oP4, "title:=Siscomex Carga;controltype:=UIA_PaneControlTypeId", $TreeScope_Children); | |
;~ Local $oP6 = _UIA_getObjectByFindAll($oP5, "title:=Operação realizada com sucesso.;controltype:=UIA_TextControlTypeId", $TreeScope_Children); | |
;~ ;Local $oP4 = _UIA_getObjectByFindAll($oP3, "controltype:=UIA_ImageControlTypeId;iaccessiblevalue:=https://www4c.receita.fazenda.gov.br/carga-web/captcha.jpg", $TreeScope_Descendants); | |
;~ if IsObj($oP6) Then | |
;~ _ObjectManager_ListChildren($oP6) | |
;~ ;_ObjectManager_ShowProperty(5, $oP5) | |
;~ Else | |
;~ ConsoleWrite("Não é Objeto" & @CRLF) | |
;~ EndIf | |
; =========================================================================================== | |
; EXEMPLO DE COMO BUSCAR UM OBJETO, FAZER BUSCA EM CASO DE FALHA, RETORNAR ATRIBUTO | |
; =========================================================================================== | |
; ------ Para Buscar um objeto adicionar a biblioteca ------ | |
;#include "../../lib/objectManager.au3" | |
; ------ Use o UIA_Spy para achar a propriedades e monte em forma de array: ------ | |
; ------ Lembre de alterar o tamanho do array para o numero de elementos -------- | |
;Local $errorBox[3]; | |
;$errorBox[0] = "Title:=Importar Arquivo;controltype:=UIA_WindowControlTypeId;class:=TfImportArq01"; | |
;$errorBox[1] = "Title:=Error;controltype:=UIA_WindowControlTypeId;class:=#32770"; | |
;$errorBox[2] = "ControlType:=UIA_TextControlTypeId;class:=Element"; | |
;----- Use _ObjectManager_getObject para buscar o objeto, passando o array, no segundo argumento coloque true para debugar ---- | |
;----- Depois de Finalizado remova o ultimo argumento ----- | |
;$object = _ObjectManager_getObject($errorBox, true); | |
;~ if IsObj($object) Then | |
;~ MsgBox(0, Default, "Encontrado") | |
;~ Else | |
;~ MsgBox(0, Default, "Não encontrado") | |
;~ EndIf | |
;------ Se no Log não encontrar algum dos Objetos, será exibido uma lista das alternativas indexado, ----- | |
;------ porém é exibido apenas um resumo (title e class) parar obter os outros atributos faça: ------ | |
;------ => No Array de Objetos, comente os objetos que não encontrou ------ | |
;------ => Agora ele vai encontrar um objeto, execute o comando abaixo nele e coloque o indice do objeto q vc deseja, | |
;------ LEMBRE que vc pode ver o indice executando o comando _ObjectManager_getObject com DEBUG ativado | |
;------ => Corrija a propriedade errada e procure novamente, agora vc deve encontrar | |
;_ObjectManager_ShowProperty(1, $Object) | |
;----- Para obter uma propriedade use: | |
;consoleWrite(_UIA_getPropertyValue($object, $UIA_NamePropertyId)) | |
;------ Você deve usar uma variavel para definir a propriedad desejada, vc pode encontrar uma lista delas no começo deste arquivo | |
;----- Para Executar uma ação use | |
;_UIA_Action($errorBoxPre ,"close") | |
; REF: https://www.autoitscript.com/forum/topic/153520-iuiautomation-ms-framework-automate-chrome-ff-ie/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment