Winappdriver: GetScreenshot WinAppDriver - UnKnown Error

Created on 13 Sep 2019  路  11Comments  路  Source: microsoft/WinAppDriver

Hi,

While trying to use GetScreenshot on the WindowsElement, I'm getting the below exception:

"an unknown error occurred in the remote end while processing the command"

I tried casting the element to RemoteWebElement and then take screenshot, yet no luck.

I see that this issue is created on the similar lines, yet no proper resolution:
https://github.com/Microsoft/WinAppDriver/issues/660
Can someone please help?

Most helpful comment

@alonrbar Here it is, check if it helps you;

Bitmap bitmap = new Bitmap(currentControl.Rect.Width, currentControl.Rect.Height); //currentControl is a Windows element
using (Graphics g = Graphics.FromImage(bitmap))
g.CopyFromScreen(new Point(currentControl.Rect.Left, currentControl.Rect.Top), Point.Empty, currentControl.Rect.Size);
bitmap.Save(filePathToSave, ImageFormat.Png);

All 11 comments

this works for me:
Screenshot screenshot = session.GetScreenshot();
screenshot.SaveAsFile(screenShotFolder + filename + "_" + DateTime.Now.ToString("yyyy_MM_dd") + ".jpeg", ImageFormat.Jpeg);

Can you share the code also

I see that you are using session variable to getScreenshot, but I'm using WindowsElement in that place to get screenshot. That's the only difference.
But I have solved it by using Bitmap for capturing the image.

Thanks for the response.

@Aishwarya-UR Can you please share a snippet of how you solved it using Bitmap?
I'm having a similar issue and would love to try that too.

@alonrbar Here it is, check if it helps you;

Bitmap bitmap = new Bitmap(currentControl.Rect.Width, currentControl.Rect.Height); //currentControl is a Windows element
using (Graphics g = Graphics.FromImage(bitmap))
g.CopyFromScreen(new Point(currentControl.Rect.Left, currentControl.Rect.Top), Point.Empty, currentControl.Rect.Size);
bitmap.Save(filePathToSave, ImageFormat.Png);

@Aishwarya-UR
Amazing! Works like a charm, thank you!

By the way, you can enable syntax highlighting if you wrap the code snippet with three back ticks - see GitHub docs here. The language identifier for C# is csharp.

For instance:

Bitmap bitmap = new Bitmap(currentControl.Rect.Width, currentControl.Rect.Height); //currentControl is a Windows element

@alonrbar - Glad it helped and thanks for the tip.

@alonrbar it worked for me. thanks for the help

@abdulnoman666
No problem but I was just the one asking the question, the solution was actually shared by @Aishwarya-UR :)

@Aishwarya-UR thanks for the solution. It worked :)

Was this page helpful?
0 / 5 - 0 ratings