使用selenium.WebDriver截取屏幕截图时出现System.NullReferenceException

时间:2013-08-06 14:14:04

标签: c# selenium-webdriver

有一些问题。我正在使用带有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();

我错在哪里?

1 个答案:

答案 0 :(得分:0)

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