I need help with closing a tab in Chrome browser using JavaScript. The code snippet
js.executeScript("window.close()");
at the end of the code is not working as expected. Can someone assist me in resolving this issue?
package TestCode;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Chrome {
public static void main(String[] args) throws InterruptedException {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver","C:\\Akash\\Drivers\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://www.gmail.com");
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("window.open('https://www.facebook.com')");
Thread.sleep(5000);
js.executeScript("window.close()");
}
}