Skip to content

Commit 6225766

Browse files
committed
Use ScreenCapture for getting VisibleImage if NativeWindowHandle is zero.
1 parent dd2a8d3 commit 6225766

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/TestStack.White/UIItems/UIItem.cs

+7
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public class UIItem : IUIItem
3535
protected readonly PrimaryUIItemFactory factory;
3636
internal readonly Keyboard keyboard = Keyboard.Instance;
3737
protected IScrollBars scrollBars;
38+
private static readonly ScreenCapture ScreenCapture = new ScreenCapture();
3839
private AutomationEventHandler handler;
3940
protected readonly ILogger Logger = CoreAppXmlConfiguration.Instance.LoggerFactory.Create(typeof(UIItem));
4041

@@ -234,6 +235,12 @@ public virtual Bitmap VisibleImage
234235
{
235236
get
236237
{
238+
if (automationElement.Current.NativeWindowHandle == 0)
239+
{
240+
// In wpf controls does not have window handles, falling back to screencapture.
241+
return ScreenCapture.CaptureArea(Bounds);
242+
}
243+
237244
var displayedItem = new DisplayedItem(new IntPtr(automationElement.Current.NativeWindowHandle));
238245
using (System.Drawing.Image image = displayedItem.GetVisibleImage())
239246
return new Bitmap(image);

0 commit comments

Comments
 (0)