Search code examples
rubyspecial-characterswatir

Trying to press CRTL+T with Watir


I am building a simple script to open up a browser window with 2 different tabs. Unfortunately, the 'send_keys' function is not working when I want to use CRTL+T.

Here is my script:

require 'watir'
require 'webdrivers'
browser = Watir::Browser.new
browser.goto("http://www.google.com")
sleep(5)
browser.send_keys ([:control, 't'])
sleep(10)

Does anyone have an idea, how I can fix this?


Solution

  • Chromedriver no longer supports opening tabs via Ctrl+T - see https://bugs.chromium.org/p/chromedriver/issues/detail?id=903.

    You could open a new tab by executing JavaScript:

    browser.execute_script('window.open();')