How to handle new tab in selenium?
package newTab; import java.util.ArrayList; import org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.testng.annotations.Test; import BaseInit.BaseInit; public class newTab extends BaseInit { @Test public static void openNewTab() throws InterruptedException { driver.get("https://www.abc.com/"); Thread.sleep(2000); driver.findElement(By.xpath("//*[@id=\"mm-0\"]/div/header/div/div/div/div[1]/div[2]/div/a")).sendKeys(Keys.CONTROL, Keys.ENTER); Thread.sleep(2000); ArrayList<String> tabs = new ArrayList<String>(driver.getWindowHandles()); driver.switchTo().window(tabs.get(1)); Thread.sleep(2000); driver.switchTo().window(tabs.get(0)); } }