70749

WatiN generates empty pages

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

Answer1:

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.

Recommend

  • How to set bool value in SQL
  • WebStorm DartUnit with test api, run/debug error
  • C# Accessing Excel Worksheet
  • Is there anything like Javascript Eval in C# or Java [duplicate]
  • Why does the conditional operator always return an int in C#? [duplicate]
  • How to compare same PropertyInfo with different ReflectedType values?
  • C Inline assembly - Operand type mismatch for 'fst'
  • Does anyone have recommendations for a good (and lightweight!) PHP mailer library?
  • Eclipse and Zend Debugger breaks in the first line always, despite having unchecked that option
  • New Timeline Like Button Behavior
  • Winform Designer Application
  • Magento date text: where does it come from and how can I change it?
  • How to sort mysql coloumn that has data in Bytes KB MB GB?
  • IIS 6 not allowing periods in the querystring
  • Pytest/Allure - How to generate testcase description?
  • How does extglob work with shell parameter expansion?
  • Paramiko SSHException Channel Closed
  • Doctrine2 inverse persistance not working in nested forms
  • Update varbinary(MAX) field in SQLServer 2012 Lost Last 4 bits
  • Installing PHP 7 on digitalocean
  • Intel-64 and ia32 atomic operations acquire-release semantics and GCC 5+
  • Cannot upload to OneDrive using the new SDK
  • Do I need to reset a Perl hash index?
  • HTTP/2 streams vs HTTP/1.1 connections
  • Use of this Javascript
  • Dialing with Intent.ACTION_CALL stopps at # in phone number
  • Optimizing database types to compact database (SQLite)
  • Excel - Autoshape get it's name from cell (value)
  • Cross-Platform Protobuf Serialization
  • Check if a string to interpolate provides expected placeholders
  • Do I've to free mysql result after storing it?
  • RestKit - RKRequestDelegate does not exist
  • Traverse Array and Display in markup
  • Turn off referential integrity in Derby? is it possible?
  • How does Linux kernel interrupt the application?
  • sending mail using smtp is too slow
  • Busy indicator not showing up in wpf window [duplicate]
  • Why is Django giving me: 'first_name' is an invalid keyword argument for this function?
  • How can I use `wmic` in a Windows PE script?
  • git trying to push non-existent file … after clearing cache