Many chromedriver.exe are left hanging on Windows Selenium
By:Roy.LiuLast updated:2019-08-18
The Selenium WebDriver is closed, but the “chromedriver.exe” process is left hanging in the system. See figure :
Problem
Here is the code, a simple WebDriver example to load a URL and exists, but the chromedriver.exe never get killed.
LoadWebPageExample.java
package com.mkyong.test; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; import org.openqa.selenium.remote.DesiredCapabilities; public class LoadWebPageExample { public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe"); ChromeOptions options = new ChromeOptions(); options.addArguments("window-size=800,600"); DesiredCapabilities capabilities = DesiredCapabilities.chrome(); capabilities.setCapability(ChromeOptions.CAPABILITY, options); WebDriver driver = new ChromeDriver(capabilities); driver.get("http://google.com/"); driver.close();
Solution
This is a common mistake, to solve it, uses driver.quit() to end the automated test.
LoadWebPageExample.java
package com.mkyong.test; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; import org.openqa.selenium.remote.DesiredCapabilities; public class LoadWebPageExample { public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe"); ChromeOptions options = new ChromeOptions(); options.addArguments("window-size=800,600"); DesiredCapabilities capabilities = DesiredCapabilities.chrome(); capabilities.setCapability(ChromeOptions.CAPABILITY, options); WebDriver driver = new ChromeDriver(capabilities); driver.get("http://google.com/"); //driver.close(); driver.quit();
References
From:一号门
COMMENTS