When running Watir-Webdriver, your commands will affect the browser window that you have opened. If you open more than one browser window, your actions will still continue interacting with the parent window. If you wish to properly interact with the child browser windows, you will need to be able to switch the window you are running commands on.
at the end signifies the parent window, which will be the first browser window you opened. By switching the
, the child window will be selected, allowing you to execute commands in it. This can continue with 2,3,4,etc., increasing the index by 1 for each additional browser window. The image below demonstrates the script in action: