Sign in to follow this  
Followers 0
lastlight

Checking if Text Exists

16 posts in this topic

Hello all,

I'm a newbie to AutoIt, and I'm trying to detect whether I currently have text in a field?

It's an automation program that is tabbing through boxes, entering text if it does not already exist.

TIA!

Share this post


Link to post
Share on other sites



lastlight,

Welcome to the AutoIt forum. :mellow:

You may well have to a bit more than just TAB through the boxes if that is what you want to do. :lol: The command to do what you want is ControlGetText, but you need to define the control to read.

Have you used the Au3 Window Info Tool yet? You should find it at "C:\Program Files\AutoIt3\Au3Info.exe" if you have a standard install. It should enable you to get enough information on the boxes you are trying to fill to correctly identify them - and so allow you to read the contents. Look for the CLASS and INSTANCE details on the Control tab whan you are over the various boxes.

Give it a try and come back if you have problems. :(

M23

P.S. All the above assumes that it is a standard Windows App that you are automating - is that correct?


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

This is exactly what I need - but all control ID's or other parameters seem to be changing dynamically. Every time the application is started, the Control IDs are different. How can I code for this? Is there a function to first get the ControlID and than pass it to the next function? I would be nice if there was something like ' IF current_control.visible_text="bla, bla" then ...else...'

Thanks a lot for any tips.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Control ID's usually are different, which is why...

Look for the CLASS and INSTANCE details on the Control tab whan you are over the various boxes.

For example, if you were checking the edit control of notepad, in the id param you could put "[CLASS:Edit; INSTANCE:1]" (literally and with quotes) Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

StringInStr(WhereToSearch, WhatToSearchFor) :unsure:

Share this post


Link to post
Share on other sites

So, I should use a variable to store the value from the Control (using Class and Instance)and then use the StringInStr to check if it matches what I am looking for? Can you use variables for the string/substring parts of StringInStr? Like: StringInStr ( "$abc", "$efg")?. I could then use InputBox to enter the values.

Thanks much for everyones help.

Share this post


Link to post
Share on other sites

Yes, you can use variables as parameters for StringInStr. For example, I have a line of code like this in one of my scripts: If StringInStr($Source, GUICtrlRead($Input_Text)) = 0 Then.


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

Yes, you can use variables as parameters for StringInStr. For example, I have a line of code like this in one of my scripts: If StringInStr($Source, GUICtrlRead($Input_Text)) = 0 Then.

Thanks. This may be exactly what I need.

Share this post


Link to post
Share on other sites

You bet. Good luck with your project.


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

Hi,

ControlGetText is very inflexible for me.  I am not able to verify the existence of whatever text that I want.  It just gets a specific text and none other.  Is this true, or am I not using it right?

Thanks

Share this post


Link to post
Share on other sites

When I run the code below I get the error that I have attached.  This code is meant to click on the "Open with..." radio button in the screen that pops up in FireFox when trying to open a file, click on the "OK" button to open the PDF file, then verify the existence of the text "Cover Sheet" in the PDF file.

#region --- Au3Recorder generated code Start (v3.3.9.5 KeyboardLayout=00000409)  ---

#region --- Internal functions Au3Recorder Start ---
Func _Au3RecordSetup()
Opt('WinWaitDelay',100)
Opt('WinDetectHiddenText',1)
Opt('MouseCoordMode',0)
Local $aResult = DllCall('User32.dll', 'int', 'GetKeyboardLayoutNameW', 'wstr', '')
If $aResult[1] <> '00000409' Then
  MsgBox(64, 'Warning', 'Recording has been done under a different Keyboard layout' & @CRLF & '(00000409->' & $aResult[1] & ')')
EndIf

EndFunc

Func _WinWaitActivate($title,$text,$timeout=0)
    WinWait($title,$text,$timeout)
    If Not WinActive($title,$text) Then WinActivate($title,$text)
    WinWaitActive($title,$text,$timeout)
EndFunc

_AU3RecordSetup()
#endregion --- Internal functions Au3Recorder End ---

_WinWaitActivate("Opening","")
MouseClick("left",46,176,1)
MouseClick("left",287,297,1)
Opt("WinTitleMatchMode", 2)
ControlGetText("pdf". "Cover Sheet". "[CLASS:AVL_AVView; INSTANCE:17]")
#endregion --- Au3Recorder generated code End ---

post-87121-0-72255600-1424202430_thumb.p

Share this post


Link to post
Share on other sites

Thanks, I don't get that error anymore, but how do I verify that the text "Cover Sheet" exists in the PDF file.  I tried to do what you see in the code below, but no indication appears as to whether it passed. I don't get an error either if I try to compare $text with a text that doesn't exist in the PDF.

Local $text = ControlGetText("pdf", "Cover Sheet", "[CLASS:AVL_AVView; INSTANCE:17]")
StringInStr($text, "Cover Sheet")

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0