2

I'm aware that I can navigate backwards through my history using the IWebDriver.Navigate().Back() method, but what if I just need the URL of the last page visited? Is there a way to grab that from the WebDriver, without actually navigating there?

To be clear, this is a question about Selenium WebDriver, and has nothing to do with JavaScript.

Syndog
  • 1,531
  • 4
  • 19
  • 27
  • 2
    I've used Selenium in the past and I'm not aware of any way to do that. I also checked the documentation, Google and tried to find something using Intelisense in Visual Studio but didn't come up with anything. You would have to maintain a list (or stack) of URLs yourself to do that. – Gilles May 02 '17 at 19:21
  • @Gilles - Yeah, same here. I was hoping to avoid that, but if WebDriver has no way to peek in on its browse history, then that's what I'll do. Thanks for your efforts! – Syndog May 02 '17 at 20:08
  • Possible duplicate of [Access my entire browsing history via Javascript](http://stackoverflow.com/questions/13369829/access-my-entire-browsing-history-via-javascript) – JeffC May 02 '17 at 22:05
  • Refer [this](https://sqa.stackexchange.com/questions/8737/navigate-to-previous-page-using-selenium) post it may help you. – whatsinthename May 03 '17 at 07:25

2 Answers2

1

As suggested by several, what I ended up doing is wrapping the Selenium WebDriver in my own class that monitors all navigation, and keeps its own history. It seems a redundancy, given that somewhere deep in the bowels of WebDriver another history already exists, but since the tester doesn't have access to it, I see no other way of achieving this goal.

Thanks to all who contributed their thoughts and suggestions!

Syndog
  • 1,531
  • 4
  • 19
  • 27
0

You can just keep the previous page URL in a variable and update/pass it to the actual code that needs it. Even keep a collection of all visited URLs and just get the last item, all this will give you a history without any need for JS hacks. Storing and sharing state is a valid case, already implemented in some frameworks, like SpecFlow's ScenarioContext. And the previous page URL value will be available to all your steps/code for each test.

ekostadinov
  • 6,880
  • 3
  • 29
  • 47