Burgaud Posted September 10, 2020 Share Posted September 10, 2020 How do I get a Window's Title (that is randomized) if I know the following: 1. The folder where the exe is installed 2. Several buttons on the app are "sorta" unique from other apps. Initially, I thought of using func _FindProcess($folder) ;find 1st running process coming from $folder local $PID local $list = _FileListToArray($folder, "*.exe", 1, false) ;get only files, return filanames only if @error = 0 then for $i = 1 to $list[0] ;$list[0] = Number of Files\Folders returned ;$list[$i] = 1st File\Folder $PID = ProcessExists($list[$i]) if $PID > 0 then return $PID next endif return -1 endfunc func _FindHWND($text) local $list = WinList() ;get a list of every window for $i = 1 to $list[0][0] ;$list[0][0] = Number of windows returned ;$list[$i][0] = window title ;$list[$i][1] = window handle (HWND) if ControlGetHandle($list[$i][1], "", $text) <> 0 then return $list[$i][1] endif next return -1 endfunc Are there any simpler method to accomplish the task? 1. To get the Window's Title or PID, I prefer Title as I can use that with ControlSend() to automate clicking a button as needed by #2 below. 2. To get the handle to specific buttons on this app thanks Dan Link to comment Share on other sites More sharing options...
Danp2 Posted September 10, 2020 Share Posted September 10, 2020 It could help if you gave us some examples of this randomized title. Also what's the name of the app? Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Burgaud Posted September 10, 2020 Author Share Posted September 10, 2020 Perhaps, "random" was not a accurate word. Notepad.exe when it runs, it's Title is "Untitled - Notepad" When it loads "config.ini", the title becomes "config.ini - Notepad", etc... However, I do not have knowledge what file it opens, so i cannot predict using "[Title:This FileName - Notepad]" BUT I do not want to get the Handle of any other app that opens this file (example, VSC opening the same file); I only am interested in notepad.exe opening a random file. My problem boils down to: 1. Converting PID into HWND, or TITLE. 2. So i can use that value into ControlSend() and ControlGetText() functions. Dan. Link to comment Share on other sites More sharing options...
Danp2 Posted September 10, 2020 Share Posted September 10, 2020 Notepad... right. 🙄 P.S. By default, autoit will match a partial title. See here for more details. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Burgaud Posted September 10, 2020 Author Share Posted September 10, 2020 Thanks for the help. This topic are abundant in this forum for many years and are still relevant. There are functions for converting between Window Title and Window Handle, or getting the PID from those. But there is no function converting PID to Window Title/Window Handle. I thought, Autoit revisions would had added that function already but it is not. I ended up looping through the WinList() checking if WinGetProcess matches with the PID I had (instead of using an unreliable checking for specific buttons as posted)... 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