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.
This will navigates the browser to a specific URL.
This will navigate backward in the browser history.
This will navigates forward in the browser history.
This will reloads the current page.
Following example will cover all the navigation methods.
Java
C#
Python
Javascript
Kotlin
WebDriver driver = new ChromeDriver();
driver.get("http://localhost:8080/demo/browsers/");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(30));
// Navigate to a given URL
driver.navigate().to("http://localhost:8080/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();
IWebDriver driver = new ChromeDriver();
driver.Url = "http://localhost:8080/demo/browsers/";
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(30);
driver.Manage().Window.Maximize();
driver.Navigate().GoToUrl("http://localhost:8080/demo/home/");
driver.Navigate().Back();
driver.Navigate().Forward();
driver.Navigate().Refresh();
driver.Quit();
driver = webdriver.Chrome()
driver.get("http://loalhost:8080/demo/browsers/")
driver.maximize_window()
driver.implicitly_wait(30)
# Navigate to a given URL
driver.get("http://localhost:8080/demo/home/")
# Navigate backward in the browser history
driver.back()
# Navigate forward in the browser history
driver.forward()
# Refresh the page
driver.refresh()
driver.quit()
let driver = await new Builder().forBrowser('chrome').build();
await driver.get("http://localhost:8080/demo/browser/");
await driver.manage().window().maximize();
await driver.manage().setTimeouts({ implicit: 30000 });
// Navigate to a given URL
await driver.navigate().to("http://localhost:8080/demo/home/");
// Navigate backward in the browser history
await driver.navigate().back();
// Navigate forward in the browser history
await driver.navigate().forward();
// Refresh the page
await driver.navigate().refresh();
await driver.quit();
val driver: WebDriver = ChromeDriver()
driver["http://localhost:8080/demo/browsers/"]
driver.manage().window().maximize()
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(30))
// Navigate to a given URL
driver.navigate().to("http://localhost:8080/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()