I'm not able to close tab in chrome browser using JavaScript last line in below code js.executeScript("window.close()");
is not working. Can any one please help on the 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()"); } }
driver.windowHandles
and then close that window asdriver.close()
.. follow this link..