What am I doing wrong? My major problem is that I'm getting an error says:
error : The given path's format is not supported
I would like to save the file within the project itself under a folder I have already created named:Screenshots
public void TakeScreenShot()
{
string pth = System.Reflection.Assembly.GetCallingAssembly().CodeBase;
string actualPath = pth.Substring(0, pth.LastIndexOf("bin"));
string projectPath = new Uri(actualPath).LocalPath;
Screenshot ss = ((ITakesScreenshot)_driver).GetScreenshot();
string screenshot = ss.AsBase64EncodedString;
byte[] screenshotAsByteArray = ss.AsByteArray;
ss.SaveAsFile(projectPath+"Screenshots\\Drisha"+DateTime.Now.ToString()+".jpeg", ImageFormat.Jpeg);
}
I don't know what culture your machine is set to but I assume calling DateTime.Now.ToString() gives you something like 08/02/2017 11:41:30 which contains slashes and colons and is therefore not a valid path.
Try specifying a format inside ToString() like this:
ss.SaveAsFile(projectPath+"Screenshots\\Drisha"+DateTime.Now.ToString("ddMMyyyyHHmmss")+".jpeg", ImageFormat.Jpeg);
As a side note you should not be concatenating strings to make a path, instead use Path.Combine.
ss.SaveAsFile(Path.Combine(projectPath, "Screenshots\\Drisha", DateTime.Now.ToString("ddMMyyyyHHmmss"), ".jpeg"), ImageFormat.Jpeg);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With