def close_windows
while browser.windows.size > 1
browser.windows.last.close
end
end
Calling close_windows function after clicking a link that opens in a new window should work. This may not be the greatest solution and only applies to ensuring the first browser is the sole one open. Not much an improvement upon your answer, but maybe cleaner.