WebDriver.close() does not close browser window
Language: Java Selenium Client Version: 2.46.0 Browser: Firefox version 38.0.5 OS version: Windows 8.1
WebDriver.close() does not close browser window with 2.46.0 Everything works properly with 2.45.0 Sample code given below:
import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver;
public class GoogleApp {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.get("https://www.google.com/?gws_rd=ssl");
driver.close();
}
}
Use quit() instead of close()
I was checking this issue. It is replicable if I use firefoxdriver, but not when I use RemoteWebDriver with DesiredCapabilities.firefox(). Also, if I wait for few seconds before executing the driver.close command everything works fine.
When this doesn't work, I could see an error in browser console: NS_ERROR_FILE_NOT_FOUND: Component returned failure code: 0x80520012 (NS_ERROR_FILE_NOT_FOUND) [nsIFileOutputStream.init] From line 641, in driver-component.js
If I use quit() instead of close(), browser window closes. This is what I get in console: Jun 12, 2015 11:22:13 AM org.openqa.selenium.os.UnixProcess$SeleniumWatchDog destroyHarder INFO: Command failed to close cleanly. Destroying forcefully (v2). org.openqa.selenium.os.UnixProcess$SeleniumWatchDog@5d57a747
I think that is a bug of selenium.
@AJ-72: Unfortunately we can't properly fix this issue unless we understand what causes this "file not found" error, and what file is not found.
I've wrapped this init code in try-catch in the commit e81ad1d25735167df983bc7441aad192e21527ef, so we'll be able to get more information on the issue.
Please try to reproduce the issue with the latest selenium build: http://ci.seleniumhq.org:8080/job/Build%20All%20Java/lastSuccessfulBuild/artifact/selenium-server-standalone-latest.jar and tell us if you have got extra diagnostics for the issue.
Update: I tried the following code with different URLs and same environment as mentioned above:
import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver;
public class GoogleApp {
public static void main(String[] args) { WebDriver driver = new FirefoxDriver(); driver.get("https://www.google.com/?gws_rd=ssl"); driver.close(); } }
Only for the following two URLs the browser window is not closing.
- https://www.google.com/?gws_rd=ssl
- html page on my machine, say c:\Signin.html
Other URLs I tried are: https://www.yahoo.com/ http://www.msn.com/ http://www.nasdaq.com/ https://www.tiaa-cref.org/public/index.html
If I use quit() instead of close(), then window is closing every time with the following message in the console: Jun 15, 2015 2:31:27 PM org.openqa.selenium.os.UnixProcess$SeleniumWatchDog destroyHarder INFO: Command failed to close cleanly. Destroying forcefully (v2). org.openqa.selenium.os.UnixProcess$SeleniumWatchDog@3a609e06
@sdghole: This INFO message
- is already fixed (you can try the latest version, see the URL above),
- is not related to inability to close a window.
@barancev: I believe that latest selenium build you've mentioned above is for multi browser testing. I'm newbie to selenium. The jar file I had used before was selenium-java-2.46.0.jar. As per your suggestion, I tried with the above selenium latest build. These are my findings:
- The following code still does not close the browser window for the URL https://www.google.com/?gws_rd=ssl
import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver;
public class GoogleApp {
public static void main(String[] args) { WebDriver driver = new FirefoxDriver(); driver.get("https://www.google.com/?gws_rd=ssl"); driver.close(); } }
- quit() closes the browser window properly
@barancev I have more details for you. I modified the code to throw the error rather than wrapping it as a WebDriverError. From the stacktrace it looks like the method notifyOfCloseWindow() in driver-component.js is causing the issue (Line number 10180). Test ran fine once I commented out that line. Wonder why its not happening for remote webdriver and while debugging.
The full stack trace is below:
12:14:28.319 uncaught exception: fxdriver.files.File.prototype.append@file:///C:/Users/anand_jayaram/AppData/Local/Temp/anonymous4978259694487035002webdriver-profile/extensions/[email protected]/components/driver-component.js:723:4
fxdriver.logging.addClosureToDriverFileLogger_/<@file:///C:/Users/anand_jayaram/AppData/Local/Temp/anonymous4978259694487035002webdriver-profile/extensions/[email protected]/components/driver-component.js:4427:4
goog.debug.Logger.prototype.callPublish_@file:///C:/Users/anand_jayaram/AppData/Local/Temp/anonymous4978259694487035002webdriver-profile/extensions/[email protected]/components/driver-component.js:3657:6
goog.debug.Logger.prototype.doLogRecord_@file:///C:/Users/anand_jayaram/AppData/Local/Temp/anonymous4978259694487035002webdriver-profile/extensions/[email protected]/components/driver-component.js:3646:6
goog.debug.Logger.prototype.log@file:///C:/Users/anand_jayaram/AppData/Local/Temp/anonymous4978259694487035002webdriver-profile/extensions/[email protected]/components/driver-component.js:3603:88
goog.debug.Logger.prototype.warning@file:///C:/Users/anand_jayaram/AppData/Local/Temp/anonymous4978259694487035002webdriver-profile/extensions/[email protected]/components/driver-component.js:3622:32
goog.log.warning@file:///C:/Users/anand_jayaram/AppData/Local/Temp/anonymous4978259694487035002webdriver-profile/extensions/[email protected]/components/driver-component.js:4270:27
Utils.getNativeComponent@file:///C:/Users/anand_jayaram/AppData/Local/Temp/anonymous4978259694487035002webdriver-profile/extensions/[email protected]/components/driver-component.js:8595:4
Utils.getNativeEvents@file:///C:/Users/anand_jayaram/AppData/Local/Temp/anonymous4978259694487035002webdriver-profile/extensions/[email protected]/components/driver-component.js:8599:9
Utils.useNativeEvents@file:///C:/Users/anand_jayaram/AppData/Local/Temp/anonymous4978259694487035002webdriver-profile/extensions/[email protected]/components/driver-component.js:8618:118
notifyOfCloseWindow@file:///C:/Users/anand_jayaram/AppData/Local/Temp/anonymous4978259694487035002webdriver-profile/extensions/[email protected]/components/driver-component.js:8536:6
FirefoxDriver.prototype.close/<@file:///C:/Users/anand_jayaram/AppData/Local/Temp/anonymous4978259694487035002webdriver-profile/extensions/[email protected]/components/driver-component.js:10180:6
fxdriver.Timer.prototype.setTimeout/<.notify@file:///C:/Users/anand_jayaram/AppData/Local/Temp/anonymous4978259694487035002webdriver-profile/extensions/[email protected]/components/driver-component.js:603:4
1
After a little more debugging, it seems like issue is while executing the Utils.getNativeComponent method. If we set the native events to false, this issue doesn't occur.
It seems that some method (may be notifyOfCloseWindow) attempts to write something to the log while it is not available already.
Is there any difference on commands executed through remote webdriver and firefox driver? Shouldn't the same issue be present for remote driver as well since its the same webdriver xpi that is being used?
Please try the latest build: http://ci.seleniumhq.org:8080/job/Build%20All%20Java/lastSuccessfulBuild/artifact/selenium-server-standalone-latest.jar I hope that the abovementioned commit fixes the issue.
@barancev Yes, this fixes the issue. Does creating a unit test for this validation makes sense?
Unfortunately we have no infrastructure to make tests for logging that happens inside Firefox, hence no test.
@barancev: Yes, this fixes the issue on my environment. Thanks!
Interestingly, using 2.46 FirefoxDriver I had the opposite. quit() causes the INFO warning, close() does not. The browser, however, closes in both cases.
browser.service.process.send_signal(signal.SIGTERM) browser.quit()
solved the same issue for me.