Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to close geckodriver with selenium 3.0.0 beta

Environment: Win 7, Selenium 3.0.0 beta, FireFox- 49.0.1

System.setProperty("webdriver.gecko.driver","C:\\geckodriver.exe");

WebDriver driver=new FirefoxDriver();    

Issue 1:

Command: driver.close(); or ((FirefoxDriver) driver).kill();

Expected Result: Browser should close.

Actual Result: Browser is not closing.

Issue 2:

Command: driver.quit();

Expected Result: Browser should close.

Actual Result: Firefox crashed.

Getting Error: "Plugin container for FireFox has stopped working."

Any suggestions...

like image 315
Grs007 Avatar asked Sep 27 '16 06:09

Grs007


3 Answers

Workaround until we have concrete fix for this. Although several posts suggest this has been fixed in version 50 and above, the fact is this is not working consistently. I have installed latest version 54 on two machines of Windows 7 and driver. Quit is working fine on one and not on other with same Java and Selenium versions. As an alternative, for executing on Windows machines, the following code would help to kill all related processes of Firefox.

if (browser == "FIREFOX")) {
    try {
        Runtime.getRuntime().exec("taskkill /F /IM geckodriver.exe");
        Runtime.getRuntime().exec("taskkill /F /IM plugin-container.exe");
        Runtime.getRuntime().exec("taskkill /F /IM firefox.exe");
    } catch (IOException e) {
        e.printStackTrace();
    }
} else {
    driver.quit();
}
like image 57
SKSajjan Avatar answered Sep 28 '22 09:09

SKSajjan


driver.quit() did work for me

driver.close() did not.

Physically clicking on the close button using the mouse doesn't work.

Using Python 3.6, Selenium 3.4.3 together with geckodriver v.0.18.0 on Ubuntu 16.04.

like image 29
n1k31t4 Avatar answered Sep 28 '22 07:09

n1k31t4


Below solution is tested on Windows7 with Firefox49, Selenium 3.0.1, Python 3.5 and geckodriver-v0.11.1 and is working fine.

import os

Then call

os.system('tskill plugin-container')

before calling driver.quit()

like image 34
Jose Cherian Avatar answered Sep 28 '22 09:09

Jose Cherian