selnium截屏操作

这个算是难找的。C# ITakeScreenShot 接口来实现截图。不是ScreenShot这个坑弄了很长时间啊。

var folderLocation = Environment.CurrentDirectory.Replace("Out", "\\ScreenShot\\");
if (!Directory.Exists(folderLocation))
{
Directory.CreateDirectory(folderLocation);
}
var screenshot = ((ITakesScreenshot)driver).GetScreenshot();
var filename = new StringBuilder(folderLocation);
filename.Append(screenshotFirstName);
filename.Append(DateTime.Now.ToString("dd-mm-yyyy HH_mm_ss"));
filename.Append(imageFormat);
screenshot.SaveAsFile(filename.ToString(), System.Drawing.Imaging.ImageFormat.Png);

posted @ 2013-11-06 09:52  小毛驴  阅读(212)  评论(0编辑  收藏  举报