- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python selenium browser driver.back().
We can navigate back in the browser with Selenium webdriver. There are multiple ways to achieve this. The back() method is used to move back to the prior browser page. This method only is applicable if we jump from webpage to another.
We can also move back in the browser with the help of a Javascript Executor in Selenium. It has the execute_script() method which allows Selenium to run Javascript commands. We have to execute the Javascript command window.history.go(-1) to go back to the previous page.
Example
from selenium import webdriver driver = webdriver.Chrome (executable_path="C:\chromedriver.exe") driver.implicitly_wait(0.5) #launch a webpage driver.get("https://www.tutorialspoint.com/about/about_careers.htm") print("Current Page title: " + driver.title) #launch another webpage driver.get("https://www.tutorialspoint.com/questions/index.php") print("Current Page title: " + driver.title) #back to previous page with back() driver.back() print("Current Page title after back: " + driver.title)
Code Implementation with Javascript Executor.
from selenium import webdriver driver = webdriver.Chrome (executable_path="C:\chromedriver.exe") driver.implicitly_wait(0.5) #launch a webpage driver.get("https://www.tutorialspoint.com/about/about_careers.htm") print("Current Page title: " + driver.title) #launch another webpage driver.get("https://www.tutorialspoint.com/questions/index.php") print("Current Page title: " + driver.title) #back to previous page with execute_script() driver.execute_script("window.history.go(-1)") print("Current Page title after back: " + driver.title)
Output
- Related Articles
- How to perform back and refresh in a browser in Selenium with python?
- Get text using selenium web driver in python?
- What is Selenium Internet Explorer Driver or IE Driver?
- What is selenium web driver?
- How to get text with selenium web driver in python?
- What is Web Driver in Selenium?
- Selenium testing without browser.
- How to switch different browser tabs using Python Selenium?
- How do I pass options to the Selenium Chrome driver using Python?
- Difference between selenium RC and Web Driver?
- What is the Selenium Web Driver Architecture?
- How to invoke the Chrome browser in Selenium with python?
- How to invoke the Firefox browser in Selenium with python?
- How to invoke the IE browser in Selenium with python?
- How to close a browser session in Selenium with python?

Advertisements