driver.switchTo().window() will work only if new window is opened by any action in existing window. If you are using different drivers to open different windows then it wont work.
In such case you need to choose appropriate instance of driver to control the new window.
Suppose you have instance of webdriver
// Window 1 WebDriver chrome = new ChromeDriver() // Window 2 WebDriver firefox = new FirefoxDriver() Now use chrome whenever you want to interact with Window 1 and use firefox to interact with Window 2.