Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to refresh an already opened web page

I just want to refresh an already opened web page with Selenium.

It always opens a new browser window.

What I'm doing wrong?

from selenium import webdriver import urllib import urllib2  driver = webdriver.Firefox() driver.refresh() 
like image 771
PhilippL Avatar asked Feb 11 '15 15:02

PhilippL


People also ask

How do I refresh a web page?

While holding, press refresh ⟳. Using Chrome on mobile, go to ⋮ (Android) or … (iOS) > Settings > Privacy > Clear Browsing Data > Clear Browsing Data (iOS) or Clear Data (Android).

What does it mean to refresh your browser?

The refresh button, also known as the refresh option, is a function of all Internet browsers. It is used to ask the browser to send you the most updated version of the page you're viewing.

How do I refresh a page in Windows 10?

Click the Refresh button on the right hand side of the location bar container on the Navigation Toolbar or press "Ctrl + R" or F5 to reload a web page.


1 Answers

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') 

Documentation on keys here: http://selenium-python.readthedocs.org/en/latest/api.html

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 ?

like image 109
aberna Avatar answered Sep 21 '22 23:09

aberna