Selenium Tutorial for Beginners

Browser Navigation commands in Selenium Webdriver, with examples

Web navigation refers to the process of navigating a network of information resources in the World Wide Web, which is organized as hypertext or hypermedia. The user interface that is used to do so is called a web browser. A web browser has multiple options for navigation – open a web page URL, navigate to other webpage by clicking any element, Back, Forward or Refresh the webpage. When automating the test cases, we need to mimic user actions in the web browser. In this article we will look at some Browser Navigation commands in Selenium Webdriver, with examples. To do so, Selenium Webdriver provides Navigation interface,

  • Inherits: Object
  • Defined in: lib/selenium/webdriver/common/navigation.rb

Browser Navigation commands in Selenium Webdriver

Browser Navigation commands in Selenium Webdriver

Browser Navigation commands in Selenium Webdriver allows you to mimic the User actions in the browser. The below program demonstrates the use of these methods – navigate.to, back, forward and refresh!

navigate().to(URL);

This methods loads a new web page in the current browser window. It accepts a fully qualified URL and returns nothing. This is done using an HTTP GET operation, and the method will block until the load is complete.

You can even use the to(String) to open a web page using String variable which already stores the URL,

navigate().back();

This method is used to move back a single “item” in the web browser’s history, i.e. same operation as clicking on the browser ‘Back’ button. What if you are on the first page itself? Yeah! No action is performed. It neither accepts nor returns anything.

navigate().forward();

This method is used to move forward a single “item” in the web browser’s history, i.e. same operation as clicking on the browser ‘Forward’ button. What if you are on the latest page itself? Yeah! No action is performed. It neither accepts nor returns anything.

navigate().refresh();

This method is used to refresh the current web page, i.e. same operation as pressing F5 in the browser. It neither accepts nor returns anything.

Browser Navigation commands in Selenium Webdriver | That was easy, right? Selenium Webdriver isn’t that tough (at least for scripting) 🙂 you just need a technical mind for advanced level, i.e. designing frameworks. Until we reach that stage, keep learning and keep sharing! And don’t forget to practice…

Leave a Reply

Your email address will not be published. Required fields are marked *