Jump to content
CaptainBeardsEyesBeard

ControlGetText help

Recommended Posts

CaptainBeardsEyesBeard

Hi Guys, 

 

I've got this 

Local $hWnd = WinWait("[CLASS:Static]", "", 10)
 Local $RecordSaveSuccess = ControlGetText($hWnd, "", "Static")

WinWaitActive("Elite Enterprise Matter")
sleep(500)
ControlClick("Elite Enterprise Matter", "", "[CLASS:Button; INSTANCE:1;]")  ;click ok
Navigation_Click_OK_To_Saved_Matter() ; click ok
WinClose ( "Eliter Enterprise Matter") ; close window

MsgBox($MB_SYSTEMMODAL, "Wanker", $RecordSaveSuccess)


if $RecordSaveSuccess = StringInStr($RecordSaveSuccess, "Successfull saved") then
   MsgBox($MB_SYSTEMMODAL, "Test" & $TestCount & "  Result", "Test Passed, Matter Saved", 4)
      FileWrite($hFilehandle, @CRLF & "Test" & $TestCount & " Create a new matter using " & $MatterNumber & "as a model matter  Ensure matter saves     " & $RecordSaveSuccess)
      FileWrite($hFilehandle, @CRLF & "Test" & $TestCount & " Create a new matter using " & $MatterNumber & "as a model matter  Ensure Matter has incremented   Test Passed")

   ElseIf Then
   MsgBox($MB_SYSTEMMODAL, "Test" + $TestCount & " Result", "Test Failed", 4)
         FileWrite($hFilehandle, @CRLF & "Test" & $TestCount & " Create a new matter using " & $MatterNumber & "as a model matter   Ensure matter saves     Test Failed")
         FileWrite($hFilehandle, @CRLF & "Test" & $TestCount & " Create a new matter using " & $MatterNumber & "as a model matter   Ensure Matter has incremented   Test Failed")

EndIf

When I call the MSBOX to output the variable $RecordSaveSuccess the msgbox is empty as well as the FileWrite of $RecordSaveSuccess  

So I have 2 questions : how do I properly grab the content of this box 

 

 

And why was the test "passing" rather than failing when it saw my $RecordSaveSuccess was empty? 

 

 

1.png

Share this post


Link to post
Share on other sites
rcmaehl
10 minutes ago, CaptainBeardsEyesBeard said:

 

Local $hWnd = WinWait("[CLASS:Static]", "", 10)
 Local $RecordSaveSuccess = ControlGetText($hWnd, "", "Static")

WinWaitActive("Elite Enterprise Matter")
sleep(500)
ControlClick("Elite Enterprise Matter", "", "[CLASS:Button; INSTANCE:1;]")  ;click ok
Navigation_Click_OK_To_Saved_Matter() ; click ok
WinClose ( "Eliter Enterprise Matter") ; close window

MsgBox($MB_SYSTEMMODAL, "Wanker", $RecordSaveSuccess)


if $RecordSaveSuccess = StringInStr($RecordSaveSuccess, "Successfull saved") then
   MsgBox($MB_SYSTEMMODAL, "Test" & $TestCount & "  Result", "Test Passed, Matter Saved", 4)
      FileWrite($hFilehandle, @CRLF & "Test" & $TestCount & " Create a new matter using " & $MatterNumber & "as a model matter  Ensure matter saves     " & $RecordSaveSuccess)
      FileWrite($hFilehandle, @CRLF & "Test" & $TestCount & " Create a new matter using " & $MatterNumber & "as a model matter  Ensure Matter has incremented   Test Passed")

   ElseIf Then
   MsgBox($MB_SYSTEMMODAL, "Test" + $TestCount & " Result", "Test Failed", 4)
         FileWrite($hFilehandle, @CRLF & "Test" & $TestCount & " Create a new matter using " & $MatterNumber & "as a model matter   Ensure matter saves     Test Failed")
         FileWrite($hFilehandle, @CRLF & "Test" & $TestCount & " Create a new matter using " & $MatterNumber & "as a model matter   Ensure Matter has incremented   Test Failed")

EndIf

 

A couple things from your code:

  • Successfull saved, did you mean Successfully saved
  • You're comparing a String $RecordSaveSuccess to a Integer value StringInStr. Which will cause issues and probably always return true
  • ElseIf Then, did you mean Else?

Example with these issues fixed:
 

Local $hWnd = WinWait("[CLASS:Static]", "", 10)
Local $RecordSaveSuccess = ControlGetText($hWnd, "", "Static")

WinWaitActive("Elite Enterprise Matter")
sleep(500)
ControlClick("Elite Enterprise Matter", "", "[CLASS:Button; INSTANCE:1;]")  ;click ok
Navigation_Click_OK_To_Saved_Matter() ; click ok
WinClose ( "Eliter Enterprise Matter") ; close window

MsgBox($MB_SYSTEMMODAL, "Wanker", $RecordSaveSuccess)


if StringInStr($RecordSaveSuccess, "Successfully saved") then
   MsgBox($MB_SYSTEMMODAL, "Test" & $TestCount & "  Result", "Test Passed, Matter Saved", 4)
      FileWrite($hFilehandle, @CRLF & "Test" & $TestCount & " Create a new matter using " & $MatterNumber & "as a model matter  Ensure matter saves     " & $RecordSaveSuccess)
      FileWrite($hFilehandle, @CRLF & "Test" & $TestCount & " Create a new matter using " & $MatterNumber & "as a model matter  Ensure Matter has incremented   Test Passed")

   Else
   MsgBox($MB_SYSTEMMODAL, "Test" + $TestCount & " Result", "Test Failed", 4)
         FileWrite($hFilehandle, @CRLF & "Test" & $TestCount & " Create a new matter using " & $MatterNumber & "as a model matter   Ensure matter saves     Test Failed")
         FileWrite($hFilehandle, @CRLF & "Test" & $TestCount & " Create a new matter using " & $MatterNumber & "as a model matter   Ensure Matter has incremented   Test Failed")

EndIf

 

Edited by rcmaehl

My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

My Projects
Cisco FinesseGithubIRC UDFWindowEx UDF

 

Share this post


Link to post
Share on other sites
CaptainBeardsEyesBeard

Damn that's annoying. 

So I guess the next question is how do I pull the data out the control boxcorrectly? 

And how do I check if "Successfully saved" is in the string I pull out? 

 

Thanks 

Share this post


Link to post
Share on other sites
Bilgus

well you for sure need to move 

Local $hWnd = WinWait("[CLASS:Static]", "", 10)
Local $RecordSaveSuccess = ControlGetText($hWnd, "", "Static")

to after

WinClose ( "Eliter Enterprise Matter") ; close window

 

Edited by Bilgus

Share this post


Link to post
Share on other sites
CaptainBeardsEyesBeard

Why would I do that? 

The close window function closes the window with the content I'm looking for (that a matter has been saved). 

 

 

Share this post


Link to post
Share on other sites
Bilgus

also WinWait Active Passes back an Hwnd

Local $hWnd_EEM = WinWaitActive("Elite Enterprise Matter")
sleep(500)
ControlClick($hWnd_EEM, "", "[CLASS:Button; INSTANCE:1;]")  ;click ok
Navigation_Click_OK_To_Saved_Matter($hWnd_EEM) ; click ok
WinClose ( $hWnd_EEM) ; close window
....


Func Navigation_Click_OK_To_Saved_Matter($hWnd)
...
..Click..($hwnd)..
EndFunc

 

Share this post


Link to post
Share on other sites
Bilgus

if you can check the status of a successful save before saving it then what good does it do?

Share this post


Link to post
Share on other sites
rcmaehl
5 minutes ago, Bilgus said:

well you for sure need to move 

Local $hWnd = WinWait("[CLASS:Static]", "", 10)
Local $RecordSaveSuccess = ControlGetText($hWnd, "", "Static")

to after

WinClose ( "Eliter Enterprise Matter") ; close window

 

Not sure where you're getting this from...


My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

My Projects
Cisco FinesseGithubIRC UDFWindowEx UDF

 

Share this post


Link to post
Share on other sites
CaptainBeardsEyesBeard

Hmm not sure what you guys mean. (Pretty new to autoIT!)

I'll start from the beginning 

So after saving a matter this window pops up (on the left) 

I would like to take out the string from this box which says "Successfully saved records for ABA110-1297168" 

Run an if statement to check if the variable contains "Successfully saved" 

If it does PASS TEST then output to a text file 

If it doens't contain "Successfully saved" fail test and output to a text file. 

1.png

Edited by CaptainBeardsEyesBeard

Share this post


Link to post
Share on other sites
Bilgus

Extra context helps I was reading your missing function in the script 

'Navigation_Click_OK_To_Saved_Matter() ; click ok'

as when you actually save the record

Local $hWnd = WinWait("Elite Enterprise Matter", "Successfully saved", 10)
Sleep(500)
If $hWnd Then
    ControlClick($hWnd, "", "[CLASS:Button; INSTANCE:1;]") ;click ok
    ;;;? ? ? Navigation_Click_OK_To_Saved_Matter() ; click ok
    WinClose("Eliter Enterprise Matter") ; close window

    MsgBox($MB_SYSTEMMODAL, "Test" & $TestCount & "  Result", "Test Passed, Matter Saved", 4)
    FileWrite($hFilehandle, @CRLF & "Test" & $TestCount & " Create a new matter using " & $MatterNumber & "as a model matter  Ensure matter saves     " & "Test Passed")
    FileWrite($hFilehandle, @CRLF & "Test" & $TestCount & " Create a new matter using " & $MatterNumber & "as a model matter  Ensure Matter has incremented   Test Passed")

Else
    ;Maybe?? WinClose("Eliter Enterprise Matter") ; close window
    MsgBox($MB_SYSTEMMODAL, "Test" + $TestCount & " Result", "Test Failed", 4)
    FileWrite($hFilehandle, @CRLF & "Test" & $TestCount & " Create a new matter using " & $MatterNumber & "as a model matter   Ensure matter saves     Test Failed")
    FileWrite($hFilehandle, @CRLF & "Test" & $TestCount & " Create a new matter using " & $MatterNumber & "as a model matter   Ensure Matter has incremented   Test Failed")

EndIf

 

Share this post


Link to post
Share on other sites
CaptainBeardsEyesBeard

So if I'm understanding this correctly - 

It will wait until a window with a title of "Elite Enterprise Matter" and text inside of "Successfully saved" comes up before executing further?

 

Because ideally I want to grab the full text in the box (so I can output this to a test case with the matter number) as well as to check the matter number is incrementing 

Edited by CaptainBeardsEyesBeard

Share this post


Link to post
Share on other sites
Bilgus

Win wait Should match with that partial text if you need the record number still the after a successful match do this

$sRecord = StringReplace(WinGetText($hWnd, ""), "Successfully saved records for "); or use regexp to parse out a valid record number

;If $Record <> "" Then

If you can't get the text to match then switch to

[Title:Elite Enterprise Matter; CLASS:Static]

 

Share this post


Link to post
Share on other sites
Bilgus

And It will wait 10 seconds for that title before failing

Local $hWnd = WinWait("Elite Enterprise Matter", "Successfully saved", 10) ; waits 10 seconds

Local $hWnd = WinWait("Elite Enterprise Matter", "Successfully saved") ; Waits FOREVER

 

Share this post


Link to post
Share on other sites
CaptainBeardsEyesBeard
13 minutes ago, Zedna said:

In your first post change this (incorrect):

Local $hWnd = WinWait("[CLASS:Static]", "", 10)
Local $RecordSaveSuccess = ControlGetText($hWnd, "", "Static")

to this (correct):

Local $hWnd = WinWait("Elite Enterprise Matter", "", 10)
Local $RecordSaveSuccess = ControlGetText($hWnd, "", "Static2")

Thanks man this sorted it. 

 

Share this post


Link to post
Share on other sites
CaptainBeardsEyesBeard
48 minutes ago, rcmaehl said:

A couple things from your code:

  • Successfull saved, did you mean Successfully saved
  • You're comparing a String $RecordSaveSuccess to a Integer value StringInStr. Which will cause issues and probably always return true
  • ElseIf Then, did you mean Else?

Example with these issues fixed:
 

Local $hWnd = WinWait("[CLASS:Static]", "", 10)
Local $RecordSaveSuccess = ControlGetText($hWnd, "", "Static")

WinWaitActive("Elite Enterprise Matter")
sleep(500)
ControlClick("Elite Enterprise Matter", "", "[CLASS:Button; INSTANCE:1;]")  ;click ok
Navigation_Click_OK_To_Saved_Matter() ; click ok
WinClose ( "Eliter Enterprise Matter") ; close window

MsgBox($MB_SYSTEMMODAL, "Wanker", $RecordSaveSuccess)


if StringInStr($RecordSaveSuccess, "Successfully saved") then
   MsgBox($MB_SYSTEMMODAL, "Test" & $TestCount & "  Result", "Test Passed, Matter Saved", 4)
      FileWrite($hFilehandle, @CRLF & "Test" & $TestCount & " Create a new matter using " & $MatterNumber & "as a model matter  Ensure matter saves     " & $RecordSaveSuccess)
      FileWrite($hFilehandle, @CRLF & "Test" & $TestCount & " Create a new matter using " & $MatterNumber & "as a model matter  Ensure Matter has incremented   Test Passed")

   Else
   MsgBox($MB_SYSTEMMODAL, "Test" + $TestCount & " Result", "Test Failed", 4)
         FileWrite($hFilehandle, @CRLF & "Test" & $TestCount & " Create a new matter using " & $MatterNumber & "as a model matter   Ensure matter saves     Test Failed")
         FileWrite($hFilehandle, @CRLF & "Test" & $TestCount & " Create a new matter using " & $MatterNumber & "as a model matter   Ensure Matter has incremented   Test Failed")

EndIf

 

This if statement now works for me

 

All working now! Many thanks! 

Edited by CaptainBeardsEyesBeard
  • Like 1

Share this post


Link to post
Share on other sites
Earthshine

what did you learn today?


My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
rcmaehl
26 minutes ago, Earthshine said:

what did you learn today?

Mitochondria is the powerhouse of the cell.... no wait that was middle school.

  • Like 1

My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

My Projects
Cisco FinesseGithubIRC UDFWindowEx UDF

 

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

×