Skip to content
CodeKruPro

Go back and forward in the browser history

Automation taskEasyAsked in: Accenture, Infosys, TCS, Wipro

A common question: "What is the difference between get() and navigate(), and how do you go back, forward and refresh?" Here you move through the history and print the title after each step, so you can see where the browser is at every point.

Browser Back and Forward Navigation

Video walkthrough

Watch on YouTube

Browser Back and Forward Navigation

Selenium can simulate browser back/forward buttons:

  • driver.navigate().back() - goes to previous page
  • driver.navigate().forward() - goes to next page
  • driver.navigate().refresh() - refreshes current page

Task:

  1. Navigate to https://testkru.com/Elements/TextFields
  2. Navigate to https://testkru.com/Elements/Buttons
  3. Go back and print the title
  4. Go forward and print the title

Expected output:

After back: Text Fields
After forward: Buttons