Browser Navigation

In Selenium, browser navigation refers to the process of interacting with the browser's navigation history, including actions like navigating to a URL, refreshing the page, moving backward or forward in the browsing history, etc. Selenium provides methods in the WebDriver interface to perform these navigation actions.

Following are the navigation methods used by selenium.

Navigate to a URL

This will navigates the browser to a specific URL.

Navigate Backward

This will navigate backward in the browser history.

Navigate Forward

This will navigates forward in the browser history.

Refresh the Page

This will reloads the current page.

Following example will cover all the navigation methods.

Java
C#
Python
Javascript
Kotlin
Copy
WebDriver driver = new ChromeDriver();
driver.get("https://www.testautomationstudio.com/demo/browser/");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(30));
// Navigate to a given URL
driver.navigate().to("https://www.testautomationstudio.com/demo/home/");
// Navigate backward in the browser history
driver.navigate().back();
// Navigate forward in the browser history
driver.navigate().forward();
// Refresh the page
driver.navigate().refresh();
driver.quit();
Copy
IWebDriver driver = new ChromeDriver();
driver.Url = "https://www.testautomationstudio.com/demo/misc/";
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(30);
driver.Manage().Window.Maximize();
driver.Navigate().GoToUrl("https://www.testautomationstudio.com/demo/home/");
driver.Navigate().Back();
driver.Navigate().Forward();
driver.Navigate().Refresh();
driver.Quit();
Python code coming soon
Javascript code coming soon
Kotlin code coming soon