Reputation: 91
I have written a scrapper using selenium which uses chrome driver. It works well but some time it fails to quit chrome driver with following exception
org.openqa.selenium.WebDriverException: Timed out waiting for driver server to stop.
Build info: version: '4.1.3', revision: '7b1ebf28ef'
System info: host: '45-79-216-229.ip.linodeusercontent.com', ip: '45.79.216.229', os.name: 'Linux', os.arch: 'amd64', os.version: '4.18.0-348.12.2.el8_5.x86_64', java.version: '11.0.14'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Command: [66aa12cc87af0a6cf095436a6bbece90, quit {}]
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 102.0.5005.61, chrome: {chromedriverVersion: 102.0.5005.61 (0e59bcc00cc4..., userDataDir: /tmp/.com.google.Chrome.DhJaWB}, goog:chromeOptions: {debuggerAddress: localhost:45009}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: LINUX, platformName: LINUX, proxy: Proxy(), se:cdp: ws://localhost:45009/devtoo..., se:cdpVersion: 102.0.5005.61, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:virtualAuthenticators: true}
Session ID: 66aa12cc87af0a6cf095436a6bbece90
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:132)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:567)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:622)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:626)
at org.openqa.selenium.remote.RemoteWebDriver.quit(RemoteWebDriver.java:463)
at org.openqa.selenium.chromium.ChromiumDriver.quit(ChromiumDriver.java:293)
Code I am adding my code here.
public class SeleniumScraper {
private WebDriver driver;
public SeleniumScraper() {
WebDriverManager.chromedriver().setup();
ChromeOptions options = this.getDefaultChromeOptions();
this.driver = new ChromeDriver(options);
driver.manage().window().maximize();
}
public WebDriver getPage(String url) {
this.driver.get(url);
return driver;
}
public boolean quitDriver() {
this.driver.quit();
return true;
}
protected ChromeOptions getDefaultChromeOptions() {
HashMap<String, Object> chromePrefs = new HashMap<>(2);
chromePrefs.put("profile.default_content_settings.popups", false);
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", chromePrefs);
options.setHeadless(true);
return options;
}
}
Upvotes: 1
Views: 1649
Reputation: 91
I tried
driver.close();
driver.quit();
it does not throw any exception now.
Upvotes: 2