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

What is data driven testing?

API Automation Testing Script to check Response

How to handle frame window in selenium?

How to work with mouse hover menu in selenium?

How does Selenium Webdriver handle SSL certificate in Chrome?