C# Selenium - 如何在 Visual Studio 2015 中截取屏幕截图 [英] C# Selenium - How do you take a screenshot in Visual Studio 2015
问题描述
在使用 selenium 和 C# 在 Visual Studio 2015 中截取屏幕截图时,我需要一些帮助.运行下面的代码时,我不断收到错误消息.
I need some help when it comes to taking a screenshot in visual studio 2015 using selenium and C#. I keep getting an error message when running the code below.
Screenshot ss = ((ITakesScreenshot)driver).GetScreenshot();
ss.SaveAsFile(@"C:\Temp\Download\Image.png",
ScreenshotImageFormat.Png);
我收到的错误消息是System.Runtime.InteropServices.ExternalExcepton:GDI+ 中发生一般错误"
The error message I get is "System.Runtime.InteropServices.ExternalExcepton: A generic error occurred in GDI+"
如果目前有人能够截取屏幕截图,请告诉我您的做法是否有所不同.
If anyone is currently able to take screenshots, please let me know if you are doing anything differently.
推荐答案
终于!
我发现我设置文件路径的方式有问题,我将初始代码更改为以下代码,现在它可以工作了.
I found that there was an issue with the way that I had the file path setup, I changed my initial code to the following code and now it's working.
Screenshot ss = ((ITakesScreenshot)driver).GetScreenshot();
ss.SaveAsFile("C://Image.png",
ScreenshotImageFormat.Png);
注意这将节省您的 C: 驱动器.
Note This will save on your C: drive.
这篇关于C# Selenium - 如何在 Visual Studio 2015 中截取屏幕截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!