How to perform back and refresh in a browser in Selenium with python?


We can perform back and refresh in the browser in Selenium.

For performing back operation in the browser, the back method is to be used.

For refreshing the browser, refresh method is to be used.

Both these methods can be used for testing browser navigations and reloading of web pages.

Example

Code Implementation

from selenium import webdriver
#browser exposes an executable file
#Through Selenium test we will invoke the executable file which will then #invoke actual browser
driver = webdriver.Chrome(executable_path="C:\chromedriver.exe")
# to maximize the browser window
driver.maximize_window()
#get method to launch the URL
driver.get("https://www.tutorialspoint.com/index.htm")
# to print the page title in console
print(driver.title)
# to print the current URL in console
print(driver.current_url)
#get method to launch another URL
driver.get("https://www.tutorialspoint.com/questions/index.php")
# to go back to the previous URL
driver.back()
#to refresh the browser
driver.refresh()
#to close the browser
driver.close()

Updated on: 29-Jul-2020

498 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements