Sign in to follow this  
Followers 0
MrPanda

WinGetTitle Return 0

7 posts in this topic

#1 ·  Posted (edited)

Hello all,

Very new user to AutoIt but loving it so far, currently using AutoIt v3.3.6.1; and having a problem with the return value “0” with the WinGetTitle Function (so when it can’t find a Title returning 0); I’ve broken my code out to a very basic check on Google just for testing to make sure I am understanding it correctly (so no, I am not just randomly checking Google :-).

The problem I have is when WinGetTitle returns “0” or can’t find a title, my ‘Case $var = 0’ does not detect it (but my test message box does show that 0 in the message box...but when I’m on any Google Page other than Google Maps, it seems to think that ‘Case $var = 0’ is true and hits this case versus the ‘Case Else’.

What am I doing wrong or is my understanding of the return value incorrect? I’ve tried looking all over and trying different combinations of quotes etc. or even $var <= 1 etc.

WinGetTitleTest.au3

On a side note, is there a way in a text variable, example

$var1 = “this is a test of ability”

To have it look for just a string inside it, example

If $var1 = “…test of…” Then

Thanks for the help!

Michael

Edited by MrPanda

Share this post


Link to post
Share on other sites



If you use AU3Info (found in SciTE4AutoIt3) what does it show about the window?

Hint:

WinGetTitle("[CLASS:IEFrame]", "")

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

If you use AU3Info (found in SciTE4AutoIt3) what does it show about the window?

Hint:

WinGetTitle("[CLASS:IEFrame]", "")

Well the commands work find, and it captures the title as expected, but say I do not have any IE window open that has Google in the title, my understanding is that WinGetTitle should return 0, which it does as I tested with the:

$var = WinGetTitle("Windows Internet Explorer", "Google")

MsgBox(0, "Test", $var)

and the message box successfully shows title "Test" and information 0 ... however it doesn't seem that the

Case $var = 0

works correctly as even though to me it looks like $var = 0 it does not perform this case section...

However the odd thing is say when

$var = Google - Windows Internet Explorer

it performs the Case $var = 0 which it should not it (I believe) it should be performing the Case Else section

I've included the Window info anyway:

>>>> Window <<<<

Title: Google - Windows Internet Explorer

Class: IEFrame

Position: 245, 5

Size: 1277, 853

Style: 0x14CF0000

ExStyle: 0x00000100

Handle: 0x001204C6

>>>> Control <<<<

Class:

Instance:

ClassnameNN:

Name:

Advanced (Class):

ID:

Text:

Position:

Size:

ControlClick Coords:

Style:

ExStyle:

Handle:

>>>> Mouse <<<<

Position: 422, 21

Cursor ID: 0

Color: 0x8C8A8C

>>>> StatusBar <<<<

1:

2:

3:

4:

5:

6:

7:

8:

9:

10: Internet

>>>> ToolsBar <<<<

>>>> Visible Text <<<<

Command Bar

Favorites Command Bar

Navigation Bar

Page Control

http://www.google.com/

http://www.google.com/

Bing

Search Control

Google - Windows Internet Explorer

Zoom Level

ITBarHost

Menu Bar

>>>> Hidden Text <<<<

Bing

Share this post


Link to post
Share on other sites

If you run the "WinGetTitleTest.au3" with Google open, then Google Maps Open, then say "Yahoo" open (or just no Google window open) you will see what I means.

With Google Maps Open it functions correctly as the first case is

Case $var = "Google Maps - Windows Internet Explorer" ;testing purpose, will use different (constant) URL in my script

Sleep(10000)

$var = WinGetTitle("Windows Internet Explorer", "Google")

With just no Google windows open it does not function correctly (or the way I want it to I should say :-) as it doesn't trigger any of the 'Cases' even thought $var = 0 (so should trigger case 2)

Case $var = 0 ;want to be able to identify if it could not find a title, not to just continue

MsgBox(0, "ERROR!", "No Title Found" & @CRLF & @CRLF & "Error Line 51" & @CRLF & @CRLF & "Retrying in 5 seconds", 10)

Sleep(10000)

But with any Google window open (other than Maps) it will trigger Case 2 (above) when it should trigger 'Case Else' (below)

Case Else

MsgBox(0, "Success!", "Correct page found " & $var)

What I am trying to do is there is a page that opens as a redirect (constant title), and I want to get the next page's title (varying title) so my thought was to use this as if '$var = constant title' wait 10 seconds, then try to do a WinGetTitle again...if the page failed to load or AutoIt failed to 'GetWinTitle' then $var = 0 to give error message box.

Reason I need to use WinGetTitle is that the window has a random title and I want to perform commands such as:

$PageTitle = WinGetTitle("[CLASS:IEFrame]", "&title=")

Do
    $State = ControlGetText($PageTitle, "", "msctls_statusbar321")
    Sleep(500)
    Until $State = "Done"

ControlClick($PageTitle,"", "[CLASS:ToolbarWindow32; INSTANCE:9]", "Primary",1,41,12)

I'm trying to avoid just say sleep(30000) which does work as it just waits for the redirect page to load, then the new page loads and it captures the most recent IE window.

Thank you!

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I think your problem is coming from comparing number to string value. This is little workaround until someone reply with proper solution.

Sleep(2000)
Opt("WinTitleMatchMode", 2)

$var = _WinGetTitleString("Windows Internet Explorer", "Google")

MsgBox(0, "Test", $var)

Select
    Case $var = "Google Maps - Windows Internet Explorer" ;testing purpose, will use different (constant) URL in my script
        Sleep(10000)
        $var = _WinGetTitleString("Windows Internet Explorer", "Google")
    Case $var = "" ;want to be able to identify if it could not find a title, not to just continue
        MsgBox(0, "ERROR!", "No Title Found" & @CRLF & @CRLF & "Error Line 51" & @CRLF & @CRLF & "Retrying in 5 seconds", 10)
        Sleep(10000)
        $var = _WinGetTitleString("Windows Internet Explorer", "Google")
    Case Else
        MsgBox(0, "Success!", "Correct page found " & $var)
EndSelect

MsgBox(0, "Final", $var)


Func _WinGetTitleString($title,$text)
    Local $lcTitle
    $lcTitle = WinGetTitle($title, $text)
    If IsNumber($lcTitle) Then
        Return ""
    Else
        Return $lcTitle
    EndIf
EndFunc

By the way, if all you need is Internet Explorer title, you might consider using IE.au3 UDF.

- Joon

Edited by Joon

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Thanks Joon for your response; however perhaps I am misunderstanding but it doesn't seem that _WinGetTitleString is an actual command? Do I need to include a UDF or something?

Pretty much I seem to not properly understand how I can use the return values for most of the AutoIt commands to perform "error checks", I can successfully capture them using say:

Opt("WinTitleMatchMode", 2)

$PageTitle = WinGetTitle("[CLASS:IEFrame]", "&title=")

Which when no IE window with "&title=" is open it returns the value of '0' to $PageTitle; however when I use it in Select/Case or If/Else statements it doesn't work correctly for me (If $PageTitle = 0 Then) etc.

Can someone explain how I am correctly supposed to utilize the return values? I think this would clear up many of my issues :-)

Edited by MrPanda

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Thanks Joon for your response; however perhaps I am misunderstanding but it doesn't seem that _WinGetTitleString is an actual command? Do I need to include a UDF or something?

Scroll down little more on my code example. :huh2:

FYI - A string beginning with letters has a numeric value of zero.

Edited by Joon

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