My question is very similar to this question. I launch many instances of WebDriver
and some of them don't respond to driver.quit()
. As described in this response I am able to kill browser instance by retrieving PID directly from capabilities object via the following code:
Code Block:
import java.io.IOException; import org.openqa.selenium.Capabilities; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.remote.RemoteWebDriver; public class Kill_Firefox_PID { public static void main(String[] args) throws IOException { System.setProperty("webdriver.gecko.driver", "C:\\Utility\\BrowserDrivers\\geckodriver.exe"); WebDriver driver = new FirefoxDriver(); Capabilities cap = ((RemoteWebDriver) driver).getCapabilities(); System.out.println("moz:processID value is : "+cap.getCapability("moz:processID")); Runtime.getRuntime().exec("taskkill /PID "+cap.getCapability("moz:processID")); } }
Console Output:
moz:processID value is : 8492
While this works excellently to kill browser itself I still see instances of Geckodriver
when I open task manager. As stated in the other thread I am unable to indiscriminately kill all Geckdriver
instances via taskkill /f /im geckodriver.exe
as there are some instances that are needed.
In short, I want to be able to retrieve PID of Geckodriver
via capabilities and destroy those instances of Geckodriver
(via PID) in a similar way that we are able to retrieve PID of Firefox WebDriver
as outlined in response to this question.
Is this possible?
Thanks!