Page navigation with Selenium

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:
driver.navigate().refresh();
  • To go back to the previous page:
driver.navigate().back();
  • 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):
driver.navigate().forward();
  • To go to a page whose URL you know (instead of using driver.get(“url”)):
driver.navigate().to("url");
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s