How to move back and forward in History using Selenium Python ?
Last Updated :
04 Jan, 2021
Selenium’s Python Module is built to perform automated testing with Python. Selenium Python bindings provides a simple API to write functional/acceptance tests using Selenium WebDriver. To open a webpage using Selenium Python, checkout –
Navigating links using get method – Selenium Python. Just being able to go to places isn’t terribly useful. What we’d really like to do is to interact with the pages, or, more specifically, the HTML elements within a page. There are multiple strategies to find an element using Selenium, checkout –
Locating Strategies. Selenium WebDriver offers various useful methods to control the session, or in other words, browser. For example, adding a cookie, pressing back button, navigating among tabs, etc.
This article revolves around driver methods to move forward and backward in Selenium to move backward and forward in browser history. The two major methods used are -
back driver method
back
method is used to go one step back in browser history.
Syntax -
driver.back()
Example -
Now one can use back method as a driver method as below -
driver.get("https://www.geeksforgeeks.org/")
driver.back()
To check individual implementation of back method visit -
back driver method in Selenium Python.
forward driver method
forward
method is used to go one step forward in browser history.
Syntax -
driver.forward()
Example -
Now one can use forward method as a driver method as below -
driver.get("https://www.geeksforgeeks.org/")
driver.forward()
To check individual implementation of forward method visit -
forward driver method in Selenium Python.
How to use back and forward driver methods in Selenium Python ?
To demonstrate these methods of WebDriver in Selenium Python. Let' s visit https://www.geeksforgeeks.org/ and operate on driver object.
Program -
Python3
# import webdriver
from selenium import webdriver
# create webdriver object
driver = webdriver.Firefox()
# get geeksforgeeks.org
driver.get("https://www.geeksforgeeks.org/")
# get geeksforgeeks.org
driver.get("https://www.practice.geeksforgeeks.org/")
# one step backward in browser history
driver.back()
# one step backward in browser history
driver.forward()
Output -
Browser goes backward in history as verified below -

Then, browser goes forward in history as verified below -
Similar Reads
How to Locate Elements using Selenium Python? Selenium: is an open-source tool that automates web browsers. It provides a single interface that lets you write test scripts in programming languages like Ruby, Java, NodeJS, PHP, Perl, Python, and C#, among others. I personally prefer Python as itâs very easy to write code in python. A browser-dri
3 min read
How to check if an element exists with Python Selenium? Selenium is one of the most powerful and widely used tools for web automating web applications. Whether you're a software developer or a QA tester, Selenium is an important tool to have in your toolkit. Selenium is widely used for automating user interactions like clicking buttons, filling out the f
7 min read
How to switch to new window in Selenium for Python? Selenium is the most used Python tool for testing and automation for the web. But the problem occurs when it comes to a scenario where users need to switch between windows in chrome. Hence, selenium got that cover as well. Selenium uses these methods for this task- window_handles is used for working
3 min read
move_to_element method - Action Chains in Selenium Python Seleniumâs Python Module is built to perform automated testing with Python. ActionChains are a way to automate low-level interactions such as mouse movements, mouse button actions, keypress, and context menu interactions. This is useful for doing more complex actions like hover over and drag and dro
2 min read
How to scrape multiple pages using Selenium in Python? As we know, selenium is a web-based automation tool that helps us to automate browsers. Selenium is an Open-Source testing tool which means we can easily download it from the internet and use it. With the help of Selenium, we can also scrap the data from the webpages. Here, In this article, we are g
4 min read
How to handle Frames/iFrames in Selenium with Python Selenium is an effective device for controlling an internet browser through the program. It is purposeful for all browsers, works on all fundamental OS and its scripts are written in numerous languages i.e Python, Java, C#, etc, we can be running with Python. HTML outlines are utilized to isolate yo
2 min read