How to refresh an already open web page

I just want to refresh an already open webpage with Selenium .

It always opens a new browser window.

What am I doing wrong?

 from selenium import webdriver import urllib import urllib2 driver = webdriver.Firefox() driver.refresh() 
+11
source share
4 answers

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

On OSX for example

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

Key documentation here: http://selenium-python.readthedocs.org/en/latest/api.html

Update: The following code, very similar to yours, works great for me.

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

Are you sure you loaded the driver webpage correctly before updating it?

+10
source

You can try any of the methods below to do this.

Method 1:

 driver.findElement(By.name("s")).sendKeys(Keys.F5); 

Method 2:

 driver.get(driver.getCurrentUrl()); 

method3:

 driver.navigate().to(driver.getCurrentUrl()); 

Method4:

 driver.findElement(By.name("s")).sendKeys("\uE035"); 
+1
source

The problem is that you open the web driver and then try to update it if you did not provide a URL.

All you have to do is get the desired URL before updating:

 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() 
0
source

Good idea for "driver.refresh ()"

I have one more problem: in the β€œKiosk” I have to switch between 2 pages of URLs, say, after 1 minute.

How can I solve this?

Hi, Martin

-1
source

Source: https://habr.com/ru/post/982333/


All Articles