Jump to content

Checking if Text Exists


Recommended Posts

  • Moderators

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?

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

  • 1 year later...

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.

Link to comment
Share on other sites

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.

Link to comment
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.

Link to comment
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.

Link to comment
Share on other sites

  • 3 years later...

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

Link to comment
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")
Link to comment
Share on other sites

  • 4 years later...
  • Developers

@shreya,

I realize you just posted in a 9 years old thread which is totally unrelated to your question?
Anyways: Post your current script and show some more detailed information about the information you (want to) retrieve and what isn't working.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...