This post will show you how to force Google Chrome to open a new window rather than a new tab for the purposes of testing web applications using Webdriver’s fork for Chrome, Chromedriver.

We hit this snag while building out some cross browser tests for one of our clients using Webdriver’s Chromedriver to run the test on a Chrome browser. The problem arose with our attach popup method not being able to handle tabs in Chrome as it does modal popup’s and new windows in IE or Firefox. If you have been researching how to turn off tabbed browsing in Google Chrome’s options panel you have probably already found out that there are no options for turning this feature off unlike in Microsoft’s Internet Explorer or Mozilla’s Firefox.

This lack of tabbed browsing option in Chrome can lead to serious problems when building UI and usability tests for a web application that you want to work across the various browsers. If you build your test cases to  expect a popup or new window to be displayed when a link is clicked but a new tab shows up instead, your tests will fail to gain the handle of the new tab and subsequently any validations from that page will fail.

Editing the Registry

In order to address this issue and keep our tests moving forward on all browser types we looked into a few solutions. The first thing we tried was editing the registry to add a new declaration to the default browser http registry settings that we found on via this post. Here are the steps:

  1. Go to HKEY_CLASSES_ROOThttpshellopencommand
  2. You should see one key, named (Default). Double click this to get an editing popup.
  3. At the end of the Value data: field you should see the text -- "%1". Change this to --new-window "%1".

Unfortunately, we could never get this solution to work as promised from the post. Maybe you will have better luck with that.

Right-Clicking

We looked into right-clicking the link and choosing open in a new window, but that this ended up being an unnecessary tedious & complicated process.

Our Solution – Using Keystrokes with Chromedriver

For our solution we employed some of the new keystroke features in the latest build of Webdriver and Chromedriver. This feature allows you to send keystrokes along with the interaction as additional parameters. In this example, we are sending a shift along with the click, which in Chrome will open the link in a new window rather than Chromes tabbed browsing default. In Firefox it would be a ctrl click.