While running tests with Selenium, you might want to navigate between the pages that are opening, without knowing or caring about the URL that is assigned to them. You would like to use the browser’s back and forward functionality, to just go back one page from the current one, or forward to the next page. You might also want to refresh the current page, without performing a driver.get(“someURL”).
For these kind of navigation actions from within Selenium tests, the following methods can be used (on an instance of WebDriver type, in this case named ‘driver’):
- To refresh the current page:
- To go back to the previous page:
- To go to the next page (if the next page exists, for example if you go back from a page, then want to return to it; if there is no next page, it doesn’t do anything):
- To go to a page whose URL you know (instead of using driver.get(“url”)):