TimRude Posted April 28, 2022 Share Posted April 28, 2022 In the standard window-finding functions such as WinGetHandle, WinWait, WinExists, etc. where you specify the Title and Text as parameters, how do you look for multiple consecutive bits of text in the Text parameter? Example: A window has a number of buttons with text on it and the WindowInfo tool shows the visible text for the window to contain: Load Save Delete Copy I can specify any single one of these items as the Text parameter (i.e. 'Save'), but how would the the Text parameter of a WinGetHandle function need to be written to look for all of these items? I've tried the following without success: WinGetHandle("Some App", "LoadSaveDeleteCopy") WinGetHandle("Some App", "Load Save Delete Copy") WinGetHandle("Some App", "Load|Save|Delete|Copy") WinGetHandle("Some App", "Load" & @LF & "Save" & @LF & "Delete" & @LF & "Copy") WinGetHandle("Some App", "Load" & @CR & "Save" & @CR & "Delete" & @CR & "Copy") WinGetHandle("Some App", "Load" & @CRLF & "Save" & @CRLF & "Delete" & @CRLF & "Copy") WinGetHandle("Some App", "Load" & @TAB & "Save" & @TAB & "Delete" & @TAB & "Copy") If I do a WinGetText function on the window, it returns the above text with @LF separating the items. So it would seem like looking for them with @LF separating them would work, but it does not. Link to comment Share on other sites More sharing options...
Danp2 Posted April 28, 2022 Share Posted April 28, 2022 Can you explain why you need to detect the text on each button when locating a window? Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Solution Nine Posted April 28, 2022 Solution Share Posted April 28, 2022 Here one way : Local $hWnd = WinGetHandleEX("You apps here", "Search|Open|Reset") ConsoleWrite($hWnd & @CRLF) Func WinGetHandleEX($sTitle, $sText) Local $aList = StringSplit($sText, "|") Local $aWin = WinList($sTitle) For $i = 1 To $aWin[0][0] $sGetText = WinGetText($aWin[$i][1]) For $j = 1 to $aList[0] If Not StringInStr($sGetText, $aList[$j]) Then ContinueLoop 2 Next Return $aWin[$i][1] Next EndFunc Earthshine and pixelsearch 2 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
TimRude Posted April 28, 2022 Author Share Posted April 28, 2022 4 hours ago, Danp2 said: Can you explain why you need to detect the text on each button when locating a window? It's a matter of making sure I have the correct window. The window's title and text are commonly used as identifiers in the Win... functions, as the help info states: Quote Window Text The window text consists of all the text that AutoIt can "see". This will usually be things like the contents of edit controls (as above with "This is some text!") but will also include other text like: Button text like &Yes, &No, &Next (the & indicates an underlined letter) Dialog text like "Are you sure you wish to continue?" Control text Misc text - sometimes you don't know what it is The important thing is that you can use the text along with the title to uniquely identify a window to work with. In this case, the cumulative window text includes text from a number of controls. It's the combination of text on the window that uniquely identifies it as the "right" window I'm looking for. But I haven't been able to find a way to specify the text parameter in the Win... functions so that it can match window text coming from multiple sources on the window. Link to comment Share on other sites More sharing options...
Earthshine Posted April 28, 2022 Share Posted April 28, 2022 (edited) look at the example above you. if you know where the exe comes from that makes the window appear, you can look at the properties of the process and KNOW that is your window, verify by getting a handle and checking the controls Edited April 28, 2022 by Earthshine My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
TimRude Posted April 28, 2022 Author Share Posted April 28, 2022 1 hour ago, Nine said: Here one way : Local $hWnd = WinGetHandleEX("You apps here", "Search|Open|Reset") ConsoleWrite($hWnd & @CRLF) Func WinGetHandleEX($sTitle, $sText) Local $aList = StringSplit($sText, "|") Local $aWin = WinList($sTitle) For $i = 1 To $aWin[0][0] $sGetText = WinGetText($aWin[$i][1]) For $j = 1 to $aList[0] If Not StringInStr($sGetText, $aList[$j]) Then ContinueLoop 2 Next Return $aWin[$i][1] Next EndFunc Thanks. I had thought about writing a custom function, but was hoping I was just missing some little detail that would let the built-in functions work. And was thinking that it would be necessary to write an extender function for each of the Win... functions. But upon reflection, since a custom function like this returns the handle, it could be nested inside the calls to any of the other Win.. functions, like this: Local $Result = WinGetState(WinGetHandleEX("Some App", "Load|Save|Delete|Copy")) Not as easy as if the built-in functions could handle it natively, but a solution nonetheless. Link to comment Share on other sites More sharing options...
Danp2 Posted April 28, 2022 Share Posted April 28, 2022 @TimRudeNo need to quote the help file and I am familiar with how those functions work. 😉I just didn't understand the need to search for the text from multiple controls since using title plus text from one control is usually sufficient to uniquely identify a window. Latest Webdriver UDF Release Webdriver Wiki FAQs 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