附加后释放浏览器,不关闭它 [英] Release browser after attach, without closing it

查看:129
本文介绍了附加后释放浏览器,不关闭它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我有一个项目,我需要自动化IE(v8,但同样适用于v11,因此我认为它是通用的)。浏览器是从用户启动(或不启动),独立于我的应用程序。因此我需要附加它,并执行一个脚本。这不是WatiN的问题:

Hello,

I have a project, where I need to automate IE (v8, but the same is valid for v11 also, thus I think it is general). The browser is started (or not) from the user, independent from my application. Thus I need to attach to it, and execute a script. That is not a problem with WatiN:

IE ie = IE.AttachTo<IE>(Find.ByTitle("XYZ"),1);
ie.Eval("doit();");



到目前为止一切顺利。但我的申请不会退出。实际上 main()已经完成,没有任何语句可以执行,但应用程序仍然没有退出。除非在关闭我的应用程序之前关闭浏览器窗口。但我无法从我的应用程序中关闭它,我无法让用户关闭它 - 这是一个约束。

我必须在<$ c结束时实际杀死当前进程$ c> main()来阻止它。但这也是不可接受的,因为重新启动应用程序时自动化将不起作用。



那么,有没有办法用WatiN分离/释放附加的实例?

我也是开放形式的替代品使用浏览器就像上面的示例一样简单:查找特定窗口并在该上下文中调用脚本。



谢谢,


So far so good. But my application won't exit. Actually the main() is finished, no statement left to execute, but the application is still not exiting. Except when the browser window is closed before I am closing my application. But I can't close it from my application and I can't make the user close it either - this is a constraint.
I had to actually kill the current process at the end of main() to stop it. But this is also not acceptable as the automation won't work when the application is restarted.

So, is there any way to "detach/release" attached instance with WatiN?
I am also open form alternatives as my ineraction with the browser is as simple as the sample above: finding a specific window and calling a script int that context.

Thank you,

推荐答案

如果没有人能告诉我如何用WatiN解决这个问题,我将不得不摆脱它,并以旧的方式去做:

If no one can tell me how to solve this with WatiN, I will have to get rid of it, and do it in the old way:
foreach (SHDocVw.IWebBrowser2/*or dynamic*/ ie in shellWindows)
{
if (ie.Document.Title.Contains("XYZl"))
     ie.Document.Script.execScript("doit();", "javascript");
}



至少它是有效的,并没有挂起我的应用程序。

这是一个相当简短的解释: http://blog.likewise.org/2012/03/shdocvwshellwindows-and-iwebbrowser2- in / [ ^ ](和一些补充: http://stackoverflow.com/questions/6530083/cannot-add-c-windows-system32-shdocvw-dll-to-my-project/8541532#8541532 [ ^ ])



无论如何,我希望在WatiN中找到解决方案,但至少它不再那么紧急了。


At least it works, and does not hung my application.
Here is a quite good and short explanation for it: http://blog.likewise.org/2012/03/shdocvwshellwindows-and-iwebbrowser2-in/[^] (and some additions: http://stackoverflow.com/questions/6530083/cannot-add-c-windows-system32-shdocvw-dll-to-my-project/8541532#8541532[^])

Anyway, I am hoping for a solution in WatiN, but at least it is not that urgent anymore.


这篇关于附加后释放浏览器,不关闭它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆