How to auto-refresh the ChromeDriver using Selenium Webdriver

0 votes
I have been using Chrome auto refresh plugin in the beginning. However, now my code has multiple ChromeDriver instances opening and closing and I cannot use an auto refresh. Also, it is quite a fuss to install an auto-refresh on new computers.

Is there any way to refresh the driver (simulate F5 say every 10 seconds if the driver does not change remains motionless) with Selenium similar to the auto refresh done by Google?
May 9, 2019 in Selenium by Surya
• 970 points
13,743 views

1 answer to this question.

0 votes

You can use this command. Also, refresh is a built-in command.

driver = webdriver.Chrome()
driver.get("http://www.google.com")
driver.refresh()

Put the binary in the same folder as the python script you're writing and add the path of the browser driver

If you want to refresh every 5 seconds or more, just surround the refresh line with a while loop and add a delay. For example:

import time
while(True):
    driver.refresh()
    time.sleep(refresh_time_in_seconds)

If you wish to just refresh the page and you can see that the page hasn't changed, keep track of the page that you're on. driver.current_url is the URL of the current page. So putting it all together it would be:

import time
refresh_time_in_seconds = 15
driver = webdriver.Chrome()
driver.get("http://www.google.com")
url = driver.current_url
while(True):
    if url == driver.current_url:
        driver.refresh()
    url = driver.current_url
    time.sleep(refresh_time_in_seconds)

Another way to do this is by using this command

driver.get("some website url"); driver.navigate().refresh();

We can use actions class and mimic the key press F5

Actions act = new Actions(driver); act.SendKeys(Keys.F5).perform();

Hope this helps

answered May 10, 2019 by Vaishnavi
• 1,180 points

edited May 10, 2019 by Omkar

Related Questions In Selenium

0 votes
2 answers

How to scroll the Page up or down in Selenium WebDriver? (using java)

JavascriptExecutor jsx = (JavascriptExecutor)driver; jsx.executeScript("window.scrollBy(0,555)", ""); or Action classes ...READ MORE

answered Sep 6, 2020 in Selenium by Sri
• 3,190 points
18,966 views
0 votes
1 answer
0 votes
2 answers

How to know the exact time to load a page using Selenium WebDriver?

long start = System.currentTimeMillis(); driver.get("Some url"); long finish = ...READ MORE

answered Sep 6, 2020 in Selenium by Sri
• 3,190 points
8,047 views
0 votes
0 answers

How to configure ChromeDriver to initiate the browser in the Headless mode using Selenium?

I'm currently working on a Python script ...READ MORE

Apr 2, 2019 in Selenium by Surya
• 970 points
1,826 views
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,500 points
13,770 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
9,187 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,910 points
7,262 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,901 views
0 votes
1 answer

How to save the content on the page (full page) using Selenium WebDriver?

Selenium isn't designed to do this, you ...READ MORE

answered Jun 28, 2019 in Selenium by Vaishnavi
• 1,180 points
4,836 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP