2

有一些问题。我正在使用带有 C# 的 webdriver。这是代码

 ITakesScreenshot screenshotDriver = driver as ITakesScreenshot;
 Screenshot screenshot = screenshotDriver.GetScreenshot();
 screenshot.SaveAsFile("c:/Image_23.png", System.Drawing.Imaging.ImageFormat.Jpeg);

然后它为该行抛出 System.NullReferenceException:

 Screenshot screenshot = screenshotDriver.GetScreenshot();

我错在哪里?

4

1 回答 1

0

System.NullReferenceException当您将对象留空时会发生这种情况。在您的代码Screenshot = screenshot = screenshotDriver.GetScreenshot();中保留为空,请确保在尝试编译之前将值放入其中

于 2013-08-06T14:21:31.420 回答