A generic error occurred in GDI+ (screenshot SaveAsFile, ExternalException) A generic error occurred in GDI+ (screenshot SaveAsFile, ExternalException) selenium selenium

A generic error occurred in GDI+ (screenshot SaveAsFile, ExternalException)


Well, if anyone's curious I solved it. Turns out I'm just an idiot.

string ssPath = _persistencePath += "\\Errors";

this line was appending another \Errors to the target path on the second run though. thus invalidating the path, because \Errors\Errors didn't exist.

Thanks to everyone who commented/tried to help!


The Screenshot class doesn't dispose of the image resource properly, so it may be a bug in the Selenium framework. A work-around is to do it yourself:

public void takeScreenShot(){    string ssPath = System.IO.Path.Combine(_persistencePath, @"\Errors");    string currTime = DateTime.Now.ToString(@"MMM-ddd-d-HH.mm");    string fileName = System.IO.Path.Combine(ssPath, @"\ERROR-" + currTime + ".png");    Screenshot ss = ((ITakesScreenshot)_driver).GetScreenshot();    using (MemoryStream ms = new MemoryStream(ss.AsByteArray))    using (Image screenShotImage = Image.FromStream(ms))    {        Bitmap cp = new Bitmap(screenShotImage);        cp.Save(filename, ImageFormat.Png);        cp.Dispose();    }}

No assurance that this will fix it, but at least you can be reasonable assured that the resources are disposed of properly.

Note requires you to reference System.Drawing.dll in the project.

Edit another workaround posted.


Finally i did it!

check out this, just write completed PATHNAME,

pathname+filename+extension: @"C:\folderWithPermission\test.bmp"

JUST TAKE FOLDER WITH WRITE PERMISSIONS, was like o.0

here's the method

 public DriverExecutor CaptureScreen(string filename)    {        Screenshot shot = this.myRemoteWebDriver.GetScreenshot();        MemoryStream ms;        Image imgShot;        Bitmap bitmap;        try         {            using (ms = new MemoryStream(shot.AsByteArray))            using (imgShot = Image.FromStream(ms))            using (bitmap = new Bitmap(imgShot))            {                bitmap.Save(filename, ImageFormat.Bmp);            }        }catch(Exception err){}        return this;    } 

NOTE: im asssuming what remoteDriver was rightly instanced and encapsulated on a own object , i hope this help you all ^^