I have a scenario like clicking on the images of home page and validating page title. I am facing an issue say I am using the getTitle() function to get a page title to validate but it's returning the current URL, so my test case failed by comparing with the page title.

Here's my question: Why is it returning a current URL instead of a page title? If anyone faced this issue.

Note : This does not occur every time.

  • 1
    Is your page fully loaded when you're getting the URL?
    – FDM
    Apr 30, 2015 at 19:32
  • 1
    Add the html (title part) to your question. May 1, 2015 at 4:25
  • No, I think page is not completly loaded @ FDM
    – QAMember
    May 1, 2015 at 5:52
  • Check Locator used. it looks issue with used locator.use another locator and try it. May 1, 2015 at 7:19
  • Hello @Chetan Patel , I didn't get your point . Bcoz Is it need to use any locator in calling getTitle() function .If I am wrong in understanding your point please elaborate you answer with an example
    – QAMember
    May 1, 2015 at 7:52

2 Answers 2


Instead of using getTitle(), try the below:

WebElement title = driver.findElement(By.tagName("title"));
  • Here a small change in the above syntax driver.findElement(webdriver.By.tagName("title")).getInnerHtml().then( function(text){ console.log(text,"TEXT"); });
    – QAMember
    May 4, 2015 at 13:38
    WebDriver driver=new FirefoxDriver();
    String baseUrl="http://www.google.com";
    String expectedTitle="Google";
    String actualTitle=driver.getTitle();
        System.out.println("Test Pass");
        System.out.println("Test Failed");

it is working fine get the page Title in String and then Compare it with your Actual Title and if that matches then Test Pass

  • 1
    How does this solve the problem of getTitle() sometimes returning the page URL?
    – Kate Paulk
    May 1, 2015 at 10:47
  • no it will Not return the Page URL i am using selenium 2.42 and Mozilla 28 Version. May 1, 2015 at 11:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.