selenium icon indicating copy to clipboard operation
selenium copied to clipboard

WebDriver.close() does not close browser window

Open sdghole opened this issue 11 years ago • 18 comments

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();
}

}

sdghole avatar Jun 11 '15 23:06 sdghole

Use quit() instead of close()

dr29bart avatar Jun 12 '15 06:06 dr29bart

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

AJ-72 avatar Jun 12 '15 11:06 AJ-72

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

sdghole avatar Jun 12 '15 15:06 sdghole

I think that is a bug of selenium.

passcodex avatar Jun 15 '15 10:06 passcodex

@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.

barancev avatar Jun 15 '15 17:06 barancev

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.

  1. https://www.google.com/?gws_rd=ssl
  2. 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 avatar Jun 15 '15 18:06 sdghole

@sdghole: This INFO message

  1. is already fixed (you can try the latest version, see the URL above),
  2. is not related to inability to close a window.

barancev avatar Jun 15 '15 19:06 barancev

@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:

  1. 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(); } }

  1. quit() closes the browser window properly

sdghole avatar Jun 15 '15 23:06 sdghole

@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

AJ-72 avatar Jun 17 '15 08:06 AJ-72

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.

AJ-72 avatar Jun 17 '15 11:06 AJ-72

It seems that some method (may be notifyOfCloseWindow) attempts to write something to the log while it is not available already.

barancev avatar Jun 17 '15 11:06 barancev

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?

AJ-72 avatar Jun 17 '15 12:06 AJ-72

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 avatar Jun 22 '15 13:06 barancev

@barancev Yes, this fixes the issue. Does creating a unit test for this validation makes sense?

AJ-72 avatar Jun 23 '15 04:06 AJ-72

Unfortunately we have no infrastructure to make tests for logging that happens inside Firefox, hence no test.

barancev avatar Jun 23 '15 06:06 barancev

@barancev: Yes, this fixes the issue on my environment. Thanks!

sdghole avatar Jun 25 '15 13:06 sdghole

Interestingly, using 2.46 FirefoxDriver I had the opposite. quit() causes the INFO warning, close() does not. The browser, however, closes in both cases.

scorcoran42 avatar Jul 02 '15 19:07 scorcoran42

browser.service.process.send_signal(signal.SIGTERM) browser.quit()

solved the same issue for me.

TimurNurlygayanov avatar Jul 18 '17 14:07 TimurNurlygayanov