close

How to refresh an already opened web page

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to refresh an already opened web page in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How to refresh an already opened web page?

  1. How to refresh an already opened web page?

    The problem is you are opening the webdriver and then trying to refresh when you have not specified a URL.

  2. refresh an already opened web page

    The problem is you are opening the webdriver and then trying to refresh when you have not specified a URL.

Method 1

I would suggest binding the driver element search to the tag body and use the refresh command of the browser.

In OSX for example

driver.find_element_by_tag_name('body').send_keys(Keys.COMMAND + 'r')

Update: The following code, very similar to your one, works fine for me.

    driver = webdriver.Firefox()
    driver.get(response.url) #tested in combination with scrapy   
    time.sleep(3)   
    driver.refresh()

Are you sure you correctly load the web page with the driver before refreshing it ?

Method 2

The problem is you are opening the webdriver and then trying to refresh when you have not specified a URL.

All you need to do is get your desired URL before refreshing:

from selenium import webdriver
import urllib
import urllib2
driver = webdriver.Firefox()
driver.get("Your desired URL goes here...")
#now you can refresh the page!
driver.refresh()

Conclusion

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read