glassjellyfish24 Posted May 21, 2018 Posted May 21, 2018 I am attempting to get the text of a control who's ID changes whenever you open the application. Fortunately, I was able to write a regular expression that will match to the control's ID because it is always very similar, and only differs by a few characters each time. The problem is, StringRegExp needs test strings in order to match. Is there a way to iterate through all of the controls in a window or perhaps some other way I can get the control ID I need?
junkew Posted May 21, 2018 Posted May 21, 2018 https://www.autoitscript.com/autoit3/docs/intro/controls.htm best to read the help file FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets
glassjellyfish24 Posted May 21, 2018 Author Posted May 21, 2018 junkew, Looks like I can get it by position in the client window. Thanks
junkew Posted May 21, 2018 Posted May 21, 2018 Its also possible with iuiautomation library. See faq31 FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets
jdelaney Posted May 21, 2018 Posted May 21, 2018 There are probably better ways than position. It's possible that different resolutions will cause a diff position for the control. Or it might end up working on one computer and not another. IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Malkey Posted May 22, 2018 Posted May 22, 2018 (edited) Reviewing the array returned from the _CtrlInfo() function, note the handle and the ClassnameNN of each control are unique within the one window. The controls on the AutoIt Help window, show duplicate control id's. Provided all the tabs have been opened at least once. You can also use the "AU3Info" tool under SciTE > Tools menu to check the script's returned array for accuracy. expandcollapse popup#include <Array.au3> #include <WinAPIDlg.au3> ; http://www.autoitscript.com/forum/index.php?s=&showtopic=86287&view=findpost&p=619295 ; Be certain AutoIt Help is running. (If all tabs are clicked on before running, I get 38 controls present.) Local $WinTitle = "AutoIt Help" ; $aInfo = _CtrlInfo($WinTitle) ; Sort Array method _ArrayToClip($aInfo) ConsoleWrite(ClipGet() & @CRLF) ; For comparison of $aInfo2 array. They should be the same. _ArrayDisplay($aInfo, "ArrayDisplay", "", 0, 8, "Ctrl HWnd|ClassnameNN|Ctrl id|Ctrl class") $aInfo2 = _CtrlInfoB($WinTitle) ; Unsorted method _ArrayDisplay($aInfo2, "ArrayDisplay", "", 0, Default, "Ctrl HWnd|ClassnameNN|Ctrl id|Ctrl class") Func _CtrlInfo($WinTitle) Local $iCount = 0 $class = StringStripWS(WinGetClassList($WinTitle, ""), 2) ; $STR_STRIPTRAILING (2) = strip trailing white space $aClass = StringSplit($class, @LF, 2) ; $STR_NOCOUNT (2) = disable the return count in the first element - effectively makes the array 0-based. Local $aArray[UBound($aClass)][4] ; New 2D array. ; ================ Get ClassnameNN ================== _ArraySort($aClass) For $i = 0 To UBound($aClass) - 1 $iCount = (($i = 0 Or $aClass[$i] == $aClass[$i - 1]) ? $iCount + 1 : 1) $aArray[$i][1] = $aClass[$i] & $iCount ; ClassnameNN ; ============= End of Get ClassnameNN =============== $aArray[$i][0] = ControlGetHandle($WinTitle, "", $aArray[$i][1]) ; Handle $iCtrlid = _WinAPI_GetDlgCtrlID($aArray[$i][0]) $aArray[$i][2] = (($iCtrlid = 0) ? "" : $iCtrlid) ; Control id $aArray[$i][3] = ControlGetText($WinTitle, "", $aArray[$i][1]) ; Control text Next Return $aArray EndFunc ;==>_CtrlInfo Func _CtrlInfoB($WinTitle) Local $iInstance = 0, $sUnique = "|" $class = StringStripWS(WinGetClassList($WinTitle, ""), 2) ; $STR_STRIPTRAILING (2) = strip trailing white spaces $aClass = StringSplit($class, @LF, 2) ; $STR_NOCOUNT (2) = disable the return count in the first element - effectively makes the array 0-based. Local $aArray[UBound($aClass)][4] ; New 2D array. ; ================ Get ClassnameNN ================== For $i = 0 To UBound($aClass) - 1 $iInstance = 0 Do $iInstance += 1 Until StringInStr($sUnique, "|" & $aClass[$i] & $iInstance & "|") = 0 $aArray[$i][1] = $aClass[$i] & $iInstance ; ClassnameNN $sUnique &= $aArray[$i][1] & "|" ; Update $sUnique string for future comparisons (loops) ; ============= End of Get ClassnameNN =============== $aArray[$i][0] = ControlGetHandle($WinTitle, "", $aArray[$i][1]) ; Handle $iCtrlid = _WinAPI_GetDlgCtrlID($aArray[$i][0]) $aArray[$i][2] = (($iCtrlid = 0) ? "" : $iCtrlid) ; Control id $aArray[$i][3] = ControlGetText($WinTitle, "", $aArray[$i][1]) ; Control text Next Return $aArray EndFunc ;==>_CtrlInfoB Edited May 22, 2018 by Malkey Added leading "|" to 'Until StringInStr($sUnique, "|" & $aClass[$i] & $iInstance & "|") = 0' to ensure uniqueness.
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