How can verify page title

Like selenium IDE how i can verify page title against static text

1 Like

Hi,
you can try use this:
WebUI.openBrowser(‘URL’)

WebUI.waitForPageLoad(5, FailureHandling.STOP_ON_FAILURE)

titleWindow = WebUI.getWindowTitle()
WebUI.verifyMatch(title, “ExpectedTitle”, true)

1 Like

It works, thanks Przemek

Hi Przemek,

I tried with above code but getting nothing from getWindowTitle() method.
I got below logs:
Unable to verify match between actual text ‘’ and expected text ‘Salesforce - Enterprise Edition’ using regular expression (Root cause: Actual text ‘’ and expected text ‘Salesforce - Enterprise Edition’ are not matched using regular expression)
Pls correct me where I’m lacking.

1 Like

I’ve found the workaround by creating local variables for expected and actual results in particular et case… With Global variables I also always get the error specified above

By the way, I also found out that ig save all Global Variables to Default Execution Profile then error during execution, described by Vivek Kumar, doesn’t apper

Vivek Kumar said:

Hi Przemek,

I tried with above code but getting nothing from getWindowTitle() method.
I got below logs:
Unable to verify match between actual text ‘’ and expected text ‘Salesforce - Enterprise Edition’ using regular expression (Root cause: Actual text ‘’ and expected text ‘Salesforce - Enterprise Edition’ are not matched using regular expression)
Pls correct me where I’m lacking.

Hi,

This error is because the expression you want to verify (windows title) is NOT a regular expression. You musn’t use regex (this must be to false in the parameters of keyword verifyMatch)

Regards,

Joeyxx

1 Like

To chime in, this should work just fine for you:

title = WebUI.getWindowTitle()
WebUI.verifyMatch(title, 'expectedPageTitleGoesHere', false)

That should get you what you are looking for to verify the Page Title.

1 Like

getWindowTitle() does not always work for me. I’ve tried many things and I don’t know why sometimes it works and in other case it does not.

I’ve got the same call in two locations (one in a test case, the other in a function inside the Keywords file).

The one in the test case works, but the one in the Keywords file does not work as it always returns an empty String

The call is :
WebUI.verifyMatch(WebUI.getWindowTitle(), expectedTitle, false, FailureHandling.STOP_ON_FAILURE)

I’ve also tried using local variable and doing checks like this inside the Keyword function :

String windowTitle = WebUI.getWindowTitle()
println(windowTitle)…
if (…)

I always get an empty String and the check fails

What I need actually is to be able to put the title in a variable because the window title gets the browser name appended to it, because I’d rather do something like

if (actualTitle.contains(expectedTitle))
KeywordUtil.markPassed…
else
KeywordUtil.markFailed…

instead of having to trim the actualTitle to remove the appended browser name or other String operations…