最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Selenium Go back without refreshing - Stack Overflow

programmeradmin0浏览0评论

I want to go back from one page(say B) to previous(say A) without refreshing it. I have a page B where if I am using it manually and I press backspace key manually it goes back to page A without refreshing, but when I am using

myElement.send_keys(Keys.BACK_SPACE)

on page B its redirecting me to page A and refreshing the page.

Note: I am using selenium for python.

I want to go back from one page(say B) to previous(say A) without refreshing it. I have a page B where if I am using it manually and I press backspace key manually it goes back to page A without refreshing, but when I am using

myElement.send_keys(Keys.BACK_SPACE)

on page B its redirecting me to page A and refreshing the page.

Note: I am using selenium for python.

Share Improve this question edited Mar 21, 2016 at 18:02 Akshay Bhasin asked Mar 21, 2016 at 17:53 Akshay BhasinAkshay Bhasin 1652 gold badges3 silver badges11 bronze badges 4
  • That's usually a webpage behavior. Check the http headers of the original page response. If you see Cache-Control: must-revalidate, max-age=0 (or a part of this), Pragma: no-cache or Expires: date in the past (or even multiple ones of these headers), then the page will be reloaded always, since the server instructed the browser to do so. You can hack it with Fiddler or similar, but usually it's intentional (or defect - depending on the situation). – skandigraun Commented Mar 21, 2016 at 18:45
  • Its written as private. But still I understand you point and if this was true, then when I am manually pressing backspace on my keyboard its not reloading. Why is that happening? – Akshay Bhasin Commented Mar 21, 2016 at 18:50
  • Hmmm, indeed, you are right. Seems to be Selenium behavior. As a last idea from me, can you try setting the applicationCacheEnabled desiredCapability to true, and try again? (Also, trying the opposite of the answer of this question, enabling specifically all kind of caches, might worth a try) – skandigraun Commented Mar 21, 2016 at 18:58
  • doesn't help either. Any other scripting language that can help here? – Akshay Bhasin Commented Mar 21, 2016 at 19:13
Add a ment  | 

2 Answers 2

Reset to default 6

Use the webdriver's back() method:

browser.back()

Alternatively, use the history.back() through "execute script":

browser.execute_script("history.back();")

Try to manage tabs, than you can route between the pages without refreshing them. Open link B in a new tab then you can go back to the first tab (link A) without refreshing

发布评论

评论列表(0)

  1. 暂无评论