Software Development and QA Tips By QASource Experts

How Do You Navigate to the Previous Page in Selenium?

Written by Timothy Joseph | Aug 23, 2021 4:00:00 PM

During QA automation, there are instances when you need to go back to the previous page or move forward to the next page in browser history. WebDriver provides some basic browser navigation commands that allow the user to move backward or forward in the browser's history.

We can access the navigation methods provided by WebDriver by typing driver.navigate() in the Eclipse panel.

The first thing you will want to do after launching a browser is to open your website. This can be done with a single line of code:

driver.navigate().to("www.qasource.com ");

If you want to navigate to the previous page, you can simply use the below line of code:

driver.navigate().back();

It is just like pressing the browser’s back button. In WebDriver, this method enables the web browser to click on the back button in the existing browser window. It neither accepts anything nor returns anything. Using the inbuilt methods, you may enhance the software quality assurance services in the field of automation testing.

Need help with Selenium test automation?