user2170593
user2170593

Reputation: 11

Accessing a new browser tab using classic-watir

In my app, when you click on some links, they open the url in a new tab. I'm having trouble trying to access the new tab.

I've tried using send_keys but haven't been able to get that to work. I'm using classic-watir (1.9.0), not watir-webdriver. Unfortunately, whenever I try to search on this, I get many results referencing watir-webdriver but none referencing classic watir.

I know at some point I should upgrade to watir-webdriver, but at the moment, I really don't have the time to upgrade all my tests.

Upvotes: 1

Views: 1531

Answers (1)

Justin Ko
Justin Ko

Reputation: 46846

Attaching to tabs is the same as attaching to windows.

You can attach to the new tab:

ie2 = Watir::IE.attach(:title, 'new_windows_title')
ie2.close   #close the new tab

Or can use the window or windows method (note that this will work in both watir-classic and watir-webdriver):

#Close the last opened tab
ie.windows.last.use do
  ie.close
end

#Close a specific tab
ie.window(:title => 'new_windows_title').use do
  ie.close
end

Upvotes: 1

Related Questions