0

I am visiting a page in my spec using capybara visit and then clicking another button which is redirecting it to another page. On the third line when I print the current_path, it still shows the old (first url) rather than the second one. I am using selenium-webdriver for chrome. Any idea on why it is happening?

Edit:

Selenium is opening another browser on line 2 and not redirecting. So, its showing the url of the previous browser and not the current newly opened browser.

Rails 3.2.6 ruby 1.9.3

In the definition of current_path and current_url, it says path and url of the current page. Does current page mean the last browser that was opened?

Ava
  • 5,783
  • 27
  • 58
  • 86
  • Did you switch to using the newly opened browser window? – Justin Ko Sep 24 '12 at 21:36
  • I dont do anything. Selenium opens another browser on its own, after the command `click_button`.I was wondering is that the issue? – Ava Sep 24 '12 at 21:46
  • 1
    Yes, you have to explicitly switch to the new window. You probably want to do something like seen [here](http://stackoverflow.com/questions/7612038/with-capybara-how-do-i-switch-to-the-new-window-for-links-with-blank-targets). – Justin Ko Sep 25 '12 at 13:26
  • That helped :) Thanks a ton. You can put your comment as the answer. I will accept. – Ava Sep 25 '12 at 16:13

1 Answers1

0

You have to explicitly switch to the new window.

To work with the new window, you can do:

new_window = page.driver.browser.window_handles.last 
page.within_window new_window do
  #actions performed in new window
end
Justin Ko
  • 46,526
  • 5
  • 91
  • 101
  • Actually the following did the trick for me.`page.driver.browser.switch_to.window(page.driver.browser.window_handles.last)` – Ava Sep 25 '12 at 16:24