Selenium 4 – Browser New Window
In the Selenium 4 – Browser New Tab, we have seen how Selenium 4 allows us to open a new tab and load the url. Opening a browser new window, is almost similar. Only change we can make is the following:
Replace TAB with WINDOW
webDriver.switchTo().newWindow(WindowType.WINDOW);
Complete Test Code
package selenium4.selenium4;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WindowType;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class seleniumNewTab {
WebDriver webDriver = null;
@BeforeTest
public void beforeTest() throws InterruptedException {
System.setProperty("webdriver.chrome.driver", "C:\\Selenium\\Chrome84\\chromedriver.exe");
webDriver = new ChromeDriver();
webDriver.manage().window().maximize();
Thread.sleep(2000);
webDriver.get("https://www.gmail.com/");
}
@Test
public void checkNewTab() {
webDriver.switchTo().newWindow(WindowType.WINDOW);
webDriver.get("http://www.yahoo.co.in");
}
@AfterTest
public void afterTest() {
webDriver.quit();
}
}