Enroll in Selenium Training

Lets understand how we can do different types of navigation in a browser using the Browser Navigation Commands of IWebDriver implementation. IWebDriver interface is implemented by all the supported browser classes, hence you will find these navigation commands in all browsers. We are going to discuss about various navigation commands that we would be using in our day to day automation testing. The INavigation interface exposes the ability to move backwards and forwards in the browser’s history.

To access the navigation’s method, just type IWebDriver.navigate().. If you are using Visual studio or any IDE which supports IntelliSense, you will see the list of available navigation commands that you can use. Below is the image showing all the commands

NavigationCommandsList

We have four Navigation commands

  1. GoToUrl
  2. Back
  3. Forward
  4. Refresh

GoToUrl Command

This command is used to navigate to a particular page. Signature of this command is

void INavigation.GoToUrl(String url) : This command takes a String value of the URL as input parameter and returns void. Once this statement is executed browser navigates to the new page specified by the URL parameter.

Command - driver.Navigate().GoToUrl(appUrl);

Where appUrl is the website address to load. It is best to use a fully qualified URL.

Usage:

 driver.Navigate().GoToUrl("https://toolsqa.com");

Back Command

Back command is used to navigate to the previous page in the browser history. This is exactly similar to what happens when you click on the back button in your browser.

void INavigation.Back() : This command does not take any parameter.

Takes you back by one page on the browser’s history.

Usage:

 driver.Navigate().Back();

Forward Command

Forward command is used to navigate to the next page in the browser history. This exactly similar to what happens when you click on the forward button in your browser, if you have some history in forward direction

void INavigation.Forward() : This command does not take any parameter.

Takes you forward by one page on the browser’s history.

Usage:

driver.Navigate().Forward();

Refresh Command

This command refreshes the page as if you have pressed F5 on the browser. void INavigation.Refresh() : This command does not take any parameter

Usage:

driver.Navigate().Refresh();

Practice Exercise

  1. Launch new Browser
  2. Open DemoQA.com website
  3. Click on Registration link using “driver.findElement(By.xpath(“.//[@id=’menu-item-374′]/a”)).click();“*
  4. Come back to Home page (Use ‘Back’ command)
  5. Again go back to Registration page (This time use ‘Forward’ command)
  6. Again come back to Home page (This time use ‘To’ command)
  7. Refresh the Browser (Use ‘Refresh’ command)
  8. Close the Browser

Solution

        static void Main(string[] args)
        {
            IWebDriver driver = new InternetExplorerDriver(@"C:\Users\abc\Desktop\Server");
            driver.Navigate().GoToUrl("https://demoqa.com");

            driver.FindElement(By.XPath(".//*[@id='menu-item-374']/a")).Click();
            driver.Navigate().Back();
            driver.Navigate().Forward();
            driver.Navigate().Refresh();
            driver.Close();
        }
IWebDriver Browser Commands in C#
IWebDriver Browser Commands in C#
Previous Article
WebElement Commands in C#
WebElement Commands in C#
Next Article
Virender Singh
I am Virender Singh, I have around 14 years of experience in the Technology domain.
Reviewers
Lakshay Sharma's Photo
Lakshay Sharma

Similar Articles

Feedback