Search code examples
rubyseleniumwatir-webdriver

How do I open tabs using a Watir in ruby


I'm trying to create additional tabs in Firefox using Watir webdriver. However, I'm not having much luck

After opening the browser:

require 'watir-webdriver' b =Watir::Browser.new

I want to open up tabs but have been unable to figure out how to access the Open a New Tab button on the browser. How could I create a new tab then?


Solution

  • As already mentioned Selenium doesn't explicitly support opening of tabs, however there are 'workarounds' such as...

    require 'watir-webdriver'
    browser = Watir::Browser.new :ff
    browser.goto 'http://the-internet.herokuapp.com'
    browser.link(:text, 'A/B Testing').click(:command, :shift)
    browser.windows.last.use
    

    This will open the link in a new tab (on a mac) and focus it