String newWindow = driver.getWindowHandle(); driver.switchTo().window(newWindow); //Switching to new window driver.findElement(By.id("buttonId")); //Switching back to default/main window driver.switchTo().defaultContent();