如何刷新已经打开的网页 [英] How to refresh an already opened web page
本文介绍了如何刷新已经打开的网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我只想用Selenium
刷新一个已经打开的网页.
I just want to refresh an already opened web page with Selenium
.
它总是打开一个新的浏览器窗口.
It always opens a new browser window.
我做错了什么?
from selenium import webdriver
import urllib
import urllib2
driver = webdriver.Firefox()
driver.refresh()
推荐答案
我建议将驱动程序元素搜索绑定到标签主体,并使用浏览器的刷新命令.
I would suggest binding the driver element search to the tag body and use the refresh command of the browser.
例如在OSX中
driver.find_element_by_tag_name('body').send_keys(Keys.COMMAND + 'r')
此处有关密钥的文档: http://selenium-python.readthedocs.org/en/latest/api.html
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 ?
这篇关于如何刷新已经打开的网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文