CaptainBeardsEyesBeard Posted March 8, 2018 Posted March 8, 2018 Hi, How do I utilise the WinGetText() function? I'm writing automation tests so I would need to verify that a certain string is visible in the Visible text section of the Window Appreciate the help
Earthshine Posted March 8, 2018 Posted March 8, 2018 (edited) https://www.autoitscript.com/autoit3/docs/functions/WinGetText.htm look at the example. compare the variable you get to your data also, feel free to post you code here, even if it does not work for better help. please use the code tags located on the bar and look like <> the code tags will format the code properly Edited March 8, 2018 by Earthshine My resources are limited. You must ask the right questions
CaptainBeardsEyesBeard Posted March 8, 2018 Author Posted March 8, 2018 Thanks for the response. Perhaps WinGetText() is the wrong function for me then? Essentially I want to write a function that check the Visible text window for a piece of data then returns true (if the data is in the visible text window) or false (if the text is not in the Visible text window This is the visible text window I'm referring to. Thanks again
Earthshine Posted March 8, 2018 Posted March 8, 2018 (edited) can you please post the other tabs that the info tool gives you when you click on the control you want to check? post the Window and Control tab too please and thanks. others will be able to help you more than I, but I will try. Are you checking something in a broswer? Edited March 8, 2018 by Earthshine My resources are limited. You must ask the right questions
Earthshine Posted March 8, 2018 Posted March 8, 2018 (edited) wait, so you want to monitor the text in the Info Tool application window? usually, you use that tool to find the control you wish to manipulate. mind = boggled. please explain what app you are trying to automate. Edited March 8, 2018 by Earthshine My resources are limited. You must ask the right questions
CaptainBeardsEyesBeard Posted March 8, 2018 Author Posted March 8, 2018 OK so I have an application I want to navigate to and then to check the screen of. A basic test I'm trying to do would be to check an existing item in this Windows application. So the code looks like Switch to this active window Click here Input keys to search for an item etc. I would then automate the process of opening a new item and then doing a verification check that the data has been entered. Does that make sense? So I'm looking for a way to search if a string exists on the application window I'm currently on For instance: Search for a product ID using Send() and mouseclicks The page will have a description about the existing product "A pair of boots" (example) My test here would be: Verify string $Boots = "a pait of boots" exists on the page I'm looking at. Sorry for any confusion. I am very new to AutoIT
Earthshine Posted March 8, 2018 Posted March 8, 2018 (edited) no, just use that info tool to click on the control that contains the text. then we can get that text from the control. that's how it's done, you don't use the AutoIt Info Tool for monitoring stuff, it just gets you the info you need to talk to a given control. Do you understand? You CAN do what you want, just use the tool to click on the control that contains that text. Post it here. We can help with the rest. Edited March 8, 2018 by Earthshine My resources are limited. You must ask the right questions
CaptainBeardsEyesBeard Posted March 8, 2018 Author Posted March 8, 2018 Yeah I think I understand now. So I have the control box of this for my application... Which I got by dragging the finder tool over the field I wanted. What would be the code to get the text of that control into a string?
Earthshine Posted March 8, 2018 Posted March 8, 2018 (edited) here is a small function that waits for a control before clicking it. the part that is interesting is you could zero in on your control looking for that exact text, and, if matched, do something. expandcollapse popup#include-once #include <Timers.au3> #include "log4a.au3" ; #FUNCTION# ==================================================================================================================== ; Name ..........: _checkClickCtrl ; Description ...: Automatically wait for a control to exist. Forever or Limited ; Syntax ........: _checkClickCtrl($formclass, $text, $ctrl, $ctrltxt, $timeout, $delayafter ; Parameters ....: $formclass - Form Class info. ; $text - Windows Forms text to match ; $ctrl - Class of Copntrol ; $ctrltxt - Text of the Control you search for ; $timeout - [Optional] Timeout, Default = 0, millisecond timer ; $delayafter - [Optional] Time to delay after operation carried out ; Return values .: None ; Author ........: Earthshine ; Modified ......: ; Remarks .......: Waits for each button indefinatly. ; Logger found here: https://www.autoitscript.com/forum/topic/156196-log4a-a-logging-udf/ ; Related .......: ; Link ..........: ; Example(s) ....: _checkClickCtrl ('[CLASS:#32770]', 'ApplicationX - InstallShield Wizard', '[CLASS:Button; INSTANCE:1]', , '&Next >' 5000, 0) ; _checkClickCtrl($formclass, $text, $button2, $TD_BTN_REMOVE, 0, 0) ; _checkClickCtrl($formclass, $text, $button3, $TD_BTN_NEXT, 0, 500) ; _checkClickCtrl($formclass, $text, $button1, $TD_BTN_YES, 0, 0) ; _checkClickCtrl($formclass, $text, $button4, $TD_BTN_FINISH, 0, 0) ; =============================================================================================================================== Func _checkClickCtrl($formclass, $text, $ctrl, $ctrltxt, $timeout = 0, $delayafter = 0) _log4a_Info("_checkClickCtrl():Begin") _log4a_Info("Searching for Formclass: " & $formclass) _log4a_Info("Searching for Text: " & $text) _log4a_Info("Searching for Control: " & $ctrl) _log4a_Info("Searching for Ctrl Txt: " & $ctrltxt) _log4a_Info("Timeout: " & $timeout) _log4a_Info("Time Delay (after click): " & $delayafter) Local $time_run = _Timer_Init() While (1) If WinExists($formclass) Then Local $hCtrl = ControlGetHandle($text, '', $ctrl) If $hCtrl Then If ($timeout > 0) Then _log4a_Info(_Timer_Diff($time_run)) If (_Timer_Diff($time_run) > $timeout) Then _log4a_Info("ExitLoop:Timeout - " & $ctrl) ExitLoop EndIf EndIf Local $hCtrlHandle = ControlGetText($text, '', $ctrl) _log4a_Info("Control Text Search: " & $ctrltxt) _log4a_Info("Control Text Found: " & $hCtrlHandle) If ($hCtrlHandle == $ctrltxt) Then ; we got the handle, so the button is there ; now do whatever you need to do _log4a_Info("Found Formclass: " & $formclass) _log4a_Info("Found Text: " & $text) _log4a_Info("Found Control: " & $ctrl) _log4a_Info("Found Ctrl Txt: " & $ctrltxt) _log4a_Info("Timeout: " & $timeout) _log4a_Info("Time Delay (after click): " & $delayafter) _log4a_Info('Control [' & $ctrl & '] Clicked') ControlClick($formclass, '', $ctrl) If ($delayafter > 0) Then Sleep($delayafter) EndIf _log4a_Info("ExitLoop:Normal - " & $ctrl) ExitLoop EndIf EndIf EndIf WEnd _log4a_Info("_checkClickCtrl():End") EndFunc ;==>_checkClickCtrl You could do something similar, simple search. I log everything but you can just use ConsoleWrites if you want. just an example of how to find a control with given text for validation, or clicking in this case Edited March 8, 2018 by Earthshine My resources are limited. You must ask the right questions
Earthshine Posted March 8, 2018 Posted March 8, 2018 ON NO! That is VB6 friend. Crapola! doing control clicks and stuff probably won't work in this case. we could try something like I do above, just don't do the click part. but I am not sure that ThunderRT6 controls are able to be automated. My resources are limited. You must ask the right questions
Earthshine Posted March 8, 2018 Posted March 8, 2018 (edited) Look up ControlGetText in help; bel;ow is example from help #include <MsgBoxConstants.au3> Example() Func Example() ; Run Notepad Run("notepad.exe") ; Wait 10 seconds for the Notepad window to appear. Local $hWnd = WinWait("[CLASS:Notepad]", "", 10) ; Set the edit control in Notepad with some text. The handle returned by WinWait is used for the "title" parameter of ControlSetText. ControlSetText($hWnd, "", "Edit1", "This is some text") ; Retrieve the text of the edit control in Notepad. The handle returned by WinWait is used for the "title" parameter of ControlGetText. Local $sText = ControlGetText($hWnd, "", "Edit1") ; Display the text of the edit control. MsgBox($MB_SYSTEMMODAL, "", "The text in Edit1 is: " & $sText) ; Close the Notepad window using the handle returned by WinWait. WinClose($hWnd) EndFunc ;==>Example Edited March 8, 2018 by Earthshine My resources are limited. You must ask the right questions
CaptainBeardsEyesBeard Posted March 8, 2018 Author Posted March 8, 2018 Yeah I looked at that helpfile. Unfortunately that code doesn't seem to work as all it does is open an empty notepad file... Whereas I would expect the notepad to be populated with "This is some text" Sorry for being a pain!
Earthshine Posted March 8, 2018 Posted March 8, 2018 (edited) hey now... be nice... lol try it modified for you #include <MsgBoxConstants.au3> Example() Func Example() ; Run YOUR app Run("YourApp.exe") ; Wait 10 seconds for the YourApp window to appear. Local $hWnd = WinWait("[CLASS:ThunderRT6MDIForm]", "", 10) ; Set the edit control in Notepad with some text. The handle returned by WinWait is used for the "title" parameter of ControlSetText. ControlSetText($hWnd, "", "ThunderRT6TextBox84", "This is some text") ; Retrieve the text of the edit control in Notepad. The handle returned by WinWait is used for the "title" parameter of ControlGetText. Local $sText = ControlGetText($hWnd, "", "ThunderRT6TextBox84") ; Display the text of the edit control. MsgBox($MB_SYSTEMMODAL, "", "The text in Edit1 is: " & $sText) ; Close the Notepad window using the handle returned by WinWait. WinClose($hWnd) EndFunc ;==>Example Edited March 8, 2018 by Earthshine My resources are limited. You must ask the right questions
Earthshine Posted March 8, 2018 Posted March 8, 2018 something is wrong on your end. that notepad example works GREAT for me on Win10 and 2008 R2 Server My resources are limited. You must ask the right questions
CaptainBeardsEyesBeard Posted March 9, 2018 Author Posted March 9, 2018 Hey thanks a lot for all your help I was able to get the data I needed via Local $sText = ControlGetText($hWnd, "", "ThunderRT6TextBox84") Earthshine 1
Earthshine Posted March 9, 2018 Posted March 9, 2018 (edited) Lucky. I have to test our companies Vb 6 apps and they are not automatable hardly at all so you are lucky Edited March 9, 2018 by Earthshine My resources are limited. You must ask the right questions
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