如问题中所述,当我初始化 selenium Web 驱动程序的实例时,我的 java 程序在 main 方法完成运行后不会关闭。我正在使用 Selenium 官方文档中的示例代码:
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver", pathToWebdriver);
WebDriver driver = new FirefoxDriver();
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
try {
driver.get("https://google.com/ncr");
driver.findElement(By.name("q")).sendKeys("cheese" + Keys.ENTER);
WebElement firstResult = wait.until(presenceOfElementLocated(By.cssSelector("h3>div")));
System.out.println(firstResult.getAttribute("textContent"));
} finally {
driver.quit();
}
System.out.println(Thread.getAllStackTraces().keySet());
}
输出:
[Thread[ForkJoinPool.commonPool-worker-3,5,main], Thread[Monitor Ctrl-Break,5,main], Thread[AsyncHttpClient-3-1,5,main], Thread[Signal Dispatcher,9,system], Thread[Common-Cleaner,8,InnocuousThreadGroup], Thread[process reaper,10,system], Thread[Reference Handler,10,system], Thread[AsyncHttpClient-timer-1-1,5,main], Thread[Attach Listener,9,system], Thread[AsyncHttpClient-timer-4-1,5,main], Thread[Finalizer,8,system], Thread[main,5,main]]
PS:如果我使用 chrome webdriver 或 driver.close() 则相同
编辑:这个问题似乎只是selenium -4.0.0-alpha