dispose() 硒错误

Error in dispose() Selenium

我在 maven java 中创建了一个 selenium 脚本,它会打开一个网站并执行一些任务,有时它会自动在一个新的 window 中打开 Firefox。所以我想通过关闭所有 windows 的 Firefox 来处理这种情况。如你所知 driver.close();只会关闭一个焦点 window,所以我替换了 driver.close();用 driver.dispose();关闭所有 Firefox windows 但它在 eclipse

中显示错误
The method dispose() is undefined for the type WebDriver 

而且我认为无需在此处添加我的代码,因为我的问题是如何关闭所有 windows Firefox?或者如何使用 driver.dispose() ?谢谢

改用.quit()方法:

void quit()

Quits this driver, closing every associated window.

driver.quit();

使用 close if you want to close just the current window or quit 关闭与驱动程序关联的每个 window。