We use cookies to analyze site traffic and show personalized ads. You can accept all cookies or decline personalized advertising.
Learn more in our Privacy Policy.
Control browser history and refresh pages with WebDriver.
Browser navigation in Selenium is about controlling the browser the same way a user would with the Back, Forward, and Refresh buttons, plus typing a URL into the address bar.
driver.get("..."): The most common way. Waits for load.driver.navigate().to("..."): Alternative syntax, does the same thing.navigate().back(): Go to previous page.navigate().forward(): Go to next page.navigate().refresh(): Reload current page.Interact with the buttons to simulate navigation. Use Selenium to mimic Back, Forward, and Refresh!
12345driver.navigate().back();
driver.navigate().forward();
driver.navigate().refresh();
driver.quit();Use driver.get() for the first page load in your test, then use navigate() methods for history checks.
Don’t overuse Back/Forward in critical tests; if possible, navigate via real links or buttons in the app for more stable flows.
After a refresh(), combine navigation with assertions (e.g., current URL, labels) to verify that the application state is correct and persistent.