3

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.

Akshay Bhasin
  • 167
  • 2
  • 3
  • 11
  • 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 Mar 21 '16 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 Mar 21 '16 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](http://stackoverflow.com/questions/8009823/possible-to-disable-firefox-and-chrome-default-caching), enabling specifically all kind of caches, might worth a try) – skandigraun Mar 21 '16 at 18:58
  • doesn't help either. Any other scripting language that can help here? – Akshay Bhasin Mar 21 '16 at 19:13

2 Answers2

6

Use the webdriver's back() method:

browser.back()

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

browser.execute_script("history.back();")
Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • I tried this but its still reloading the previous page. – Akshay Bhasin Mar 21 '16 at 18:00
  • @AkshayBhasin updated with one more option, does it help? Thanks. – alecxe Mar 21 '16 at 18:03
  • Its really common that if you are using some xyz website and you press (backspace) you go back without the page being reloaded and when you press(shift+backspace) you move forward without refreshing the second page. I want to use that functionality. – Akshay Bhasin Mar 21 '16 at 18:04
  • @AkshayBhasin quick check - can you reproduce it in both Chrome and Firefox? Thanks. – alecxe Mar 21 '16 at 18:12
  • no I want to use it on firefox only as I need to manage downloads also and that can be done best when using firefox profile so. – Akshay Bhasin Mar 21 '16 at 18:13
  • @AkshayBhasin okay, please check Chrome for debugging reasons only. I want to know if your problem is browser-specific or not. Thanks! – alecxe Mar 21 '16 at 18:14
  • @AkshayBhasin thanks, to make the problem more specific, could you please provide the url(s) you are working with? (if possible) – alecxe Mar 22 '16 at 14:15
0

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

Vic Merlis
  • 11
  • 5