0

consider i am having two pages, first page -Login page and second Page -welcome page. If i provide the user credential in the login page, then it will be redirected into the welcome page.

I need to verify the page title in both the pages. so, i have used driver.getTitle(); after the page navigation steps. But, it is displaying the first page title and second page tile is not displaying

Thanks Subbu

Subburaj
  • 2,294
  • 3
  • 20
  • 37

2 Answers2

2

It's most like a timing issue - you are getting the title while the second page is not loaded yet. Use Explicit Wait via WebDriverWait class to wait for the second/welcome page to load (sample).

You may even use "title" specific wait conditions, see:

Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • I have used the title contains condition as below loginButton.submit(); WebDriverWait wait = new WebDriverWait(driver, 100); System.out.println(wait.until(ExpectedConditions.titleContains("Welcome"))); But still page name is not found correctly seems and error is throwing as "org.openqa.selenium.TimeoutException: Timed out after 100 seconds waiting for title to contain "Welcome". Current title: "Login" – Subburaj Mar 30 '16 at 16:50
  • I am getting the TimeoutException and mentioned my sample code. Please help me – Subburaj Mar 30 '16 at 16:53
  • @Subburaj oh, sorry, decided you've solved that. Okay, do you see what is happening in the browser at the moment the form is submitted? – alecxe Mar 30 '16 at 16:56
  • @Subburaj okay, we have a different issue then - I think you should elaborate this into a new question if you need the community's help. Make sure to provide as much detail as you can. Thanks. – alecxe Mar 30 '16 at 17:23
  • Hi Alecexe, I have used the above code with Firefox Driver , then it is working fine without an any issue.But when i used with IE Driver, then only page title is not getting captured correctly and getting TimeoutException. Do you have any idea on this? – Subburaj Apr 03 '16 at 17:04
  • After adding the explicit wait with titlecontains method. Page title is getting captured correctly in chrome/firefox. – Subburaj May 22 '18 at 04:36
2

you must add explicit wait and check whether second page is loading in the given time or not.