问题描述
我正在使用以下代码在 C# 中实例化 PhantomJSDriver:
I am instantiating the PhantomJSDriver in C# with this code:
Driver = new PhantomJSDriver();
并用这个清理它:
Driver.Dispose();
Driver = null;
进程应该退出还是留在内存中?如果它应该留在内存中,在 Windows 7 任务管理器中可见,我可以以编程方式杀死它吗?我应该吗?
Should the process exit or stay in memory? If it is supposed to stay in memory, visible in the Windows 7 task manager, can I kill it programmatically? Should I?
推荐答案
直接回答,Driver.Dispose();
不应该用于清理WebDriver
实例.为了进行适当的清理,我们必须使用 Driver.Quit();
.
Answering straight, Driver.Dispose();
shouldn't be used to clean up the WebDriver
instance. For a proper cleanup we must be using Driver.Quit();
.
Driver.Dispose();
:我认为已被弃用.Driver.Close();
:用于关闭当前页面或具有焦点的浏览器(如果它是唯一的页面/标签).Driver.Quit();
:用于调用/shutdown端点
,随后Web驱动程序实例被销毁,完全关闭所有页面/选项卡/窗口.
Driver.Dispose();
: I think got deprecated.Driver.Close();
: It is used to close the current page or the browser (if it is the only page/tab) which is having the focus.Driver.Quit();
: It is used to call the/shutdown endpoint
and subsequently the web driver instance is destroyed completely closing all the pages/tabs/windows.
因此调用 Driver.Quit()
方法是保证会话正确终止的唯一方法.
Hence calling the Driver.Quit()
method is the only way to guarantee that sessions are properly terminated.
在这个讨论
中,你可以找到Driver.Dispose();
、Driver.Close();
和Driver.Quit();
这篇关于PhantomJS Web 驱动程序留在内存中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!