Thursday, September 4, 2025
HomeLanguagesWebDriver Navigational Commands forward() and backward() in Selenium with Python

WebDriver Navigational Commands forward() and backward() 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.

Requirement: You need to install chromedriver and set path. Click here to download.for more information follows this link.

WebDriver Navigational Commands:

  1. forward(): takes us to the next page as per the browser history
  2. back(): takes us to the previous page as per the browser history

Procedure:

  1. Importing the modules
  2. Creating an instance of Chrome.
  3. Go to the first URL i.e. www.neveropen,com
  4. Display the title of the page.
  5. Go to the second URL i.e. www.youtube,com
  6. Display the title of the page.
  7. Go to the previous page and display the title.
  8. Go to the next page and display the title.

Implementation:

Python3




# importing the modules
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
 
# using chrome driver
driver = webdriver.Chrome()
 
# taking first url
# getting title
print(driver.title)
 
# taking 2nd url
# getting the title
print(driver.title)
 
# given time open url
time.sleep(2)
 
# WebDriver Navigational Commands backward
driver.back()
# given time open url
time.sleep(2)
# if back then given previous title
print(driver.title)
 
# WebDriver Navigational Commands backward
driver.forward()
# given time open url
time.sleep(2)
# if goto forward then given next title
print(driver.title)
 
driver.close()


Output:

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32260 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6625 POSTS0 COMMENTS
Nicole Veronica
11795 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11855 POSTS0 COMMENTS
Shaida Kate Naidoo
6746 POSTS0 COMMENTS
Ted Musemwa
7023 POSTS0 COMMENTS
Thapelo Manthata
6694 POSTS0 COMMENTS
Umr Jansen
6714 POSTS0 COMMENTS