In this post, we will learn How to refresh a browser in Selenium Python. The Selenium web driver API is used for test automation on Windows or mobile. It helps us remotely control different browsers automatically as if a real user is interacting by stimulating activities like opening or closing a new window, or tab, entering text in the textbox, selecting values from the dropdown, and mouse control.
1. How to refresh a browser in Selenium Python
In this example, We are navigating to a webpage using a driver. get() method.We are launching the Chrome browser with the help of ChromeDriverManager and driver. refresh() to refresh the already open web page. Once the webpage load The refresh of the page happened so quickly that we can’t notice it. We will use the sleep() method in the next example.
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
import time
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get("https://accounts.google.com/")
print("The First opened window = " + driver.title)
driver.refresh()
driver.close()
driver.quit()
Output
Sign in - Google Accounts
- How to Install selenium on windows Python
- How to install selenium in VSCode
- How to open chrome browser in selenium Python
- How to open Edge browser in selenium Python
- How to open Firefox browser in selenium Python
- Executable path has been deprecated in selenium Python
- Solved version of ChromeDriver only supports Chrome version 98
- How to make test suite in selenium Python
- Solved selenium find_element_by_* commands are deprecated
- How to open new tab in Selenium Python
- How to open new window Selenium Python
- How to open close tab in Selenium Python
- Python Webdrivermanager.install does not work for edge
- Load Webdrivers based user on input selenium Python
- How to switch windows in Selenium Python
- How to navigate back in selenium python
2. How to refresh a browser in Selenium Python
The selenium web driver API method driver.refresh() method is used. We are launching the Chrome browser with the help of ChromeDriverManager and navigating to the URL by the broad driver.get(“https://accounts.google.com/”) method and wait for 2 seconds and refresh the Page.
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
import time
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get("https://accounts.google.com/")
print("The First opened window = " + driver.title)
time.sleep(4)
driver.refresh()
time.sleep(4)
driver.close()
driver.quit()
Output
Sign in - Google Accounts