Contents
Pressing the Browser’s Forward Button
To simulate pressing of the browser’s forward button programmatically using Selenium for Python, call forward()
method on the Web Driver object.
driver.forward()
Example
- Initialise Chrome Web Driver object as
driver
. - Get the URL
https://pythonexamples.org/
using webdriver
object. - Find element by link text
'OpenCV'
and click on the element. - Press browser’s back button using
driver.back()
. - Press browser’s forward button using
driver.forward()
.
Python Program
from selenium.webdriver.chrome.service import Service
from selenium import webdriver
from selenium.webdriver.common.by import By
service = Service(executable_path="/usr/local/bin/chromedriver")
#initialize web driver
with webdriver.Chrome(service=service) as driver:
#navigate to the url
driver.get('https://pythonexamples.org/')
#find element that has link text : 'OpenCV' and click on it
driver.find_element(By.LINK_TEXT, 'OpenCV').click()
#press on browser's back button
driver.back()
#press on browser's forward button
driver.forward()
Screenshots
Navigation Step #1 : Get the URL https://pythonexamples.org/
.

Navigation Step #2 : Find OpenCV link and click on it.

Navigation Step #3 : Press the browser’s back button.

Navigation Step #4 : Press the browser’s forward button.

Summary
In this Python Selenium Tutorial, we learned how to press the browser’s forward button using Selenium’s driver.forward()
method.