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 in Selenium by Surya
• 860 points
95 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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 by Vaishnavi
• 860 points

edited May 10 by Omkar

Related Questions In Selenium

0 votes
1 answer

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

Its pretty simple. Check out the below ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,050 points
5,075 views
0 votes
1 answer
0 votes
1 answer

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

Normally WebDriver should return control to your ...READ MORE

answered Aug 23, 2018 in Selenium by Meci Matt
• 9,400 points
439 views
0 votes
0 answers
0 votes
1 answer

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,050 points
145 views
0 votes
1 answer
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,130 points
539 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
137 views
0 votes
1 answer
0 votes
1 answer

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.