
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 Questions & Answers
- Selenium testing without browser.
- Browser Plugin Testing With Selenium.
- Use Selenium with Chromium Browser.
- Does Selenium support Safari browser?
- Handling Browser Authentication using Selenium
- How to switch different browser tabs using Python Selenium?
- Does Selenium support headless browser testing?
- 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?
- How to perform browser navigations in Selenium?
- How to maximize the browser in Selenium?
- How to launch Chrome Browser via Selenium?
- How to start selenium browser with proxy?
Advertisements