public static WebDriver getscreenshot(String path) throws Exception
{
WebDriver driver = null;
TakesScreenshot ts = (TakesScreenshot)driver;
File scrFile = ts.getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File(path));
return driver;
}
我收到上述代码的空指针异常。
嗯,
这很正常。您已经声明了 Web 驱动程序变量,但您根本没有初始化它。尝试初始化它或从某个地方获取它,这样它就不会为空。
WebDriver driver = new WebDriver(some parameters here if any);