• Skip to main content
  • Skip to primary sidebar
  • Skip to footer
  • Home
  • Programming Languages
    • Java Tutorials
    • Python Tutorials
    • JavaScript Tutorials
  • Automation Tools and Different Tools
    • Web Automation
      • Selenium with Java
        • Selenium Basic
        • Selenium Advance
        • Selenium Realtime
        • Framework
        • Selenium Interview
        • Selenium Videos
        • Selenium with Docker
      • Selenium with Python
      • WebdriverIO
        • Selenium Webdriver C# Tutorial
      • Cypress
      • Playwright
    • TestNG
    • Cucumber
    • Mobile Automation
      • Appium
    • API Testing
      • Postman
      • Rest Assured
      • SOAPUI
    • testRigor
    • Katalon
    • TestProject
    • Serenity BDD
    • Gradle- Build Tool
    • RPA-UiPath
    • Protractor
    • Windows Automation
  • Automation For Manual Testers
  • Services
  • Online Training
  • Contact us
  • About me
  • Follow us
    • Linkedin
    • Facebook Group
    • Facebook Page
    • Instagram

Automation

Selenium WebDriver tutorial Step by Step

You are here: Home / Selenium with C# / Browser Navigation commands in Selenium with C#

Browser Navigation commands in Selenium with C#

August 23, 2018 by Mukesh Otwani 4 Comments

Selenium WebDriver has already provided many browser Navigation commands like Back, Forward, Refresh method which help us to navigate easily. This post will walk you through different type of Browser Navigation commands in Selenium with C#.

Browser Navigation commands in Selenium with C#

Navigation Commands.

Browser Navigation commands are used to perform navigation operations in browser. Navigation Commands in C# are implemented using INavigation Interface. Navigation commands available in Selenium with C# are

1 GoToUrl.

2 Back.

3 Forward

4 Refresh.

 

GoToUrl – This command is used to navigate to particular URL or website.

Signature is void INavigation.GoToUrl(String URL) – This command takes URL as string input parameter.

Syntax: driver.Navigate().GoToUrl(URL);

where URL is application url.

 

Back – This command is used to navigate back to previous webpage in browser history. This command is very similar to Back button in browser.

Signature is void INavigation.Back() – This command will not accept any parameter.

Syntax: driver.Navigate().Back();

 

Forward -This command is used to move or go to next webpage present in browser history. This command is very similar to Forward button in browser.

Signature is void INavigation.Forward() – This command will not accept any parameter.

Syntax: driver.Navigate().Forward();

 

Refresh – This command is used to refresh the webpage.

Signature is void INavigation.Refresh() – This command will not accept any parameter.

Syntax: driver.Navigate().Refresh();

 

Usage of Navigation Commands with example

 

Step 1: Create a C# project using steps discussed before. Add Selenium and Internet Explorer driver.

Step 2: Write a program which uses 4 Navigation commands.

Step 3: Code explanation is

Note- In this example I will take IE browser example and I have also detailed post I have discussed different challenges which I faced while working with IE browser and this is also the most frequently asked questions in Interview.

            //declare a driver instance
            IWebDriver driver;

            //create IE driver instance
            driver = new InternetExplorerDriver();

            //Open learn-automation.com
            driver.Navigate().GoToUrl("https://learn-automation.com/");

            //find Element with xpath and click on it
            driver.FindElement(By.XPath("//*[text()='Selenium Videos']/..")).Click();

            //click on back button using navigate
            driver.Navigate().Back();

            //click on forward button using navigate
            driver.Navigate().Forward();

            //click on refresh
            driver.Navigate().Refresh();

            //close the driver instance
            driver.Close(); 

 

 

Browser Navigation commands in Selenium with C#

 

Step 4: Build the code.

  1. Click on Build.
  2. Select Build Solution.

 

Build Solution

Note: If u get any “System.InvalidOperationException” then

  1. Click on Tools.
  2. Select Internet Options.

Then

  1. Click on
  2. Select each Internet, Local Intranet, Trusted sites, Restricted Sites.
  3. Set same Security level for all 4. Enable /Disable Protected Mode for all 4.
  4. Click on
  5. Click on OK.

IE Setting

Change Setting

 

Once settings are changed, Build again.

Once the build is successful. Start the execution by clicking on Start button.

Output

Output:

  1. IE browser will be launched.
  2. Learn-automation.com is opened.
  3. It will click on SELENIUM VIDEOS link.
  4. Browser will go back to Home page.
  5. Once the page is loaded then again browser will open Selenium videos page.
  6. Once Selenium Video Page is loaded, webpage will be refreshed.
  7. Browser will be closed.

 

Filed Under: Selenium with C# Tagged With: Browser Navigation commands in Selenium with C#

Reader Interactions

Comments

  1. Mythri says

    August 6, 2019 at 2:05 PM

    Hi Mukesh,
    I have a small doubt, for one of my testing I need test the privacy Policy, where If I click a link in my webpage, It opens a new tab with privacy policy. Can you please help me how to test that functionality

    Reply
    • Mukesh Otwani says

      August 6, 2019 at 5:14 PM

      Hi Mythri,

      This scenario is of window handling where you need to switch driver to new window/tab and verify things on corresponding page. Then close this window and switch back to previous one.

      Reply
  2. Sharrif hussain says

    December 4, 2018 at 5:38 PM

    Awsume explained

    Reply
    • Mukesh Otwani says

      December 6, 2018 at 11:22 PM

      Hi Sharrif,

      Very very thanks for your appreciation. You are always welcome to my blog…:)

      Reply

Leave a Reply Cancel reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Free Selenium Videos

https://www.youtube.com/watch?v=w_iPCT1ETO4

Search topic

Top Posts & Pages

  • Selenium Webdriver tutorial for beginners
  • How To Fix Eclipse Autocomplete Or Code Suggestion In Eclipse
  • Selenium Webdriver C# Tutorial
  • WHAT ARE YOUR EXPECTATIONS FROM US?

Stay connected via Facebook

Stay connected via Facebook

Archives

Footer

Categories

Recent Post

  • API Testing Using Postman And RestAssured
  • Disable Personalise Your Web Experience Microsoft Edge Prompt In Selenium
  • How To Fix Error: No tests found In Playwright
  • How To Fix Eclipse Autocomplete Or Code Suggestion In Eclipse
  • Best and easy way to Group test cases in selenium

Top Posts & Pages

  • Selenium Webdriver tutorial for beginners
  • How To Fix Eclipse Autocomplete Or Code Suggestion In Eclipse
  • Selenium Webdriver C# Tutorial
  • WHAT ARE YOUR EXPECTATIONS FROM US?