WatiN 生成空页

发布于 2024-07-17 23:14:16 字数 1029 浏览 1 评论 0原文

当使用 WatiN 捕获图像时,生成的图像只是空的、纯黑色的。 不过,图像的尺寸等于屏幕尺寸。 例如,以下代码片段仅保存两个黑色图像。

using (IE ie = new IE()) {
            ie.ClearCache();
            ie.BringToFront();
            ie.GoTo("http://localhost/");
            ie.CaptureWebPageToFile(imageDir + "\\localhost.png");
            WatiN.Core.CaptureWebPage capture = new CaptureWebPage(ie);
            capture.CaptureWebPageToFile(imageDir + "\\localhost.jpg", true, true, 100, 80);
            Assert.IsTrue(ie.ContainsText("Zend"));
        }

其他人也报告了这个问题,但我还没有看到任何解决方案。 请参阅此处的评论: http://www.codeproject.com/KB/graphics/IECapture.aspx?display=PrintAll&fid=192174&df=90&mpp=25& noise=3&sort=Position&view=Quick&fr=51&select=1810490

希望任何人都能对此有所了解。

干杯 // 约翰

When capturing images using WatiN the resulting images are just empty, solid black. The size of the images equals the screen size, though. For example the following snippet just saves two black images.

using (IE ie = new IE()) {
            ie.ClearCache();
            ie.BringToFront();
            ie.GoTo("http://localhost/");
            ie.CaptureWebPageToFile(imageDir + "\\localhost.png");
            WatiN.Core.CaptureWebPage capture = new CaptureWebPage(ie);
            capture.CaptureWebPageToFile(imageDir + "\\localhost.jpg", true, true, 100, 80);
            Assert.IsTrue(ie.ContainsText("Zend"));
        }

Other have reported this as well but I haven't seen any solution. See comments here:
http://www.codeproject.com/KB/graphics/IECapture.aspx?display=PrintAll&fid=192174&df=90&mpp=25&noise=3&sort=Position&view=Quick&fr=51&select=1810490

Hope any can shed some light on this.

Cheers
// John

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

司马昭之心 2024-07-24 23:14:16

我设法让它在 IE8 下的网页上工作,并进行以下更改:

替换以下方法:

private static IntPtr GetHwndForInternetExplorerServer(IntPtr hwnd)
{
    var sbc = new StringBuilder(256);
    hwnd = NativeMethods.GetWindow(hwnd, NativeMethods.GW_CHILD);
    while (hwnd != IntPtr.Zero)
    {
        NativeMethods.GetClassName(hwnd, sbc, 256);
        if (sbc.ToString().IndexOf("Shell DocObject View", 0) > -1) //IE6
        {
            hwnd = NativeMethods.FindWindowEx(hwnd, IntPtr.Zero, "Internet Explorer_Server", IntPtr.Zero);
            break;
        }
        if (sbc.ToString().IndexOf("TabWindowClass", 0) > -1) //IE7
        {
            hwnd = NativeMethods.FindWindowEx(hwnd, IntPtr.Zero, "Shell DocObject View", IntPtr.Zero);
            hwnd = NativeMethods.FindWindowEx(hwnd, IntPtr.Zero, "Internet Explorer_Server", IntPtr.Zero);
            break;
        }
        if (sbc.ToString().IndexOf("Frame Tab", 0) > -1) // IE8
        {
            hwnd = NativeMethods.FindWindowEx(hwnd, IntPtr.Zero, "TabWindowClass", IntPtr.Zero);
            hwnd = NativeMethods.FindWindowEx(hwnd, IntPtr.Zero, "Shell DocObject View", IntPtr.Zero);
            hwnd = NativeMethods.FindWindowEx(hwnd, IntPtr.Zero, "Internet Explorer_Server", IntPtr.Zero);
            break;
        }
        hwnd = NativeMethods.GetWindow(hwnd, NativeMethods.GW_HWNDNEXT);
    }
    return hwnd;
}

删除方法 GetHwndContainingAShellDocObjectView 及其调用。

I managed to get it working for my web pages under IE8 with the following changes:

Replace the following method:

private static IntPtr GetHwndForInternetExplorerServer(IntPtr hwnd)
{
    var sbc = new StringBuilder(256);
    hwnd = NativeMethods.GetWindow(hwnd, NativeMethods.GW_CHILD);
    while (hwnd != IntPtr.Zero)
    {
        NativeMethods.GetClassName(hwnd, sbc, 256);
        if (sbc.ToString().IndexOf("Shell DocObject View", 0) > -1) //IE6
        {
            hwnd = NativeMethods.FindWindowEx(hwnd, IntPtr.Zero, "Internet Explorer_Server", IntPtr.Zero);
            break;
        }
        if (sbc.ToString().IndexOf("TabWindowClass", 0) > -1) //IE7
        {
            hwnd = NativeMethods.FindWindowEx(hwnd, IntPtr.Zero, "Shell DocObject View", IntPtr.Zero);
            hwnd = NativeMethods.FindWindowEx(hwnd, IntPtr.Zero, "Internet Explorer_Server", IntPtr.Zero);
            break;
        }
        if (sbc.ToString().IndexOf("Frame Tab", 0) > -1) // IE8
        {
            hwnd = NativeMethods.FindWindowEx(hwnd, IntPtr.Zero, "TabWindowClass", IntPtr.Zero);
            hwnd = NativeMethods.FindWindowEx(hwnd, IntPtr.Zero, "Shell DocObject View", IntPtr.Zero);
            hwnd = NativeMethods.FindWindowEx(hwnd, IntPtr.Zero, "Internet Explorer_Server", IntPtr.Zero);
            break;
        }
        hwnd = NativeMethods.GetWindow(hwnd, NativeMethods.GW_HWNDNEXT);
    }
    return hwnd;
}

Remove the method GetHwndContainingAShellDocObjectView and the call to it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文