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));

}

}


Comments

Popular posts from this blog

For Get Dynamic data & USe it into Postman Body parameters

API Automation Testing Script to check Response

Login through Data Driven Testing in selenium

Which dependencies needed in pom.xml while doing automation through selenium?

Download Java(JDK) & Eclipse IDE for selenium

What is data driven testing?

How to extract all the links in selenium?