Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Controlling new tab to operate using Watir? (Ruby)

Tags:

ruby

watir

I'm using watir for automated testing and after running through some tables, a chart then gets opened up in a new tab. But watir doesn't seem to recognise the new current tab and continues to search through the original browser tab.

Is there any way of telling watir which tab you want to be using?

like image 606
samayres1992 Avatar asked Sep 17 '12 10:09

samayres1992


2 Answers

Watir does not care if a new page opens in a new window or in a new tab, so use window switching API to switch to the new tab:

browser.window(:title => "annoying popup").use do
  browser.button(:id => "close").click
end

More information: http://watirwebdriver.com/browser-popups/

like image 116
Željko Filipin Avatar answered Oct 05 '22 13:10

Željko Filipin


You can use this code

browser.windows.last.use

this will set watir focus to newly or last opened tab or window, and after completion of use of this new tab/window just tell watir to close that tab/window

browser.windows.last.close
like image 27
Gaurav Sharma Avatar answered Oct 05 '22 13:10

Gaurav Sharma