driver.close() is not working on Jenkins and the whole test will hang for forever. I am using Selenium Grid with Java and using Chrome Driver.
I don't want to user driver.quit()
. I have to use driver.close()
. I have two tabs open and i have to close one.
public static void closeBrowser()
{
try
{
WebDriver testDriver = BrowserFactory.getInstance().getDriver();
if (testDriver != null)
{
testDriver.close();
}
wait.wait(2);
Log.info("Closing the browser");
}
catch (Exception e)
{
Log.info("Cannot close browser");
}
}
This used to work and started to happen recently.
Better solution i found to close window is:
((JavascriptExecutor) BrowserFactory.getInstance().getDriver()).executeScript( "window.close()" );