2017-06-12 56 views
0
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; 
} 

我得到了上面代码的空指针异常。空指针异常即将到来

回答

0

那是正常的。你已经声明了webdriver变量,但你没有初始化它。尝试初始化它或从某处获取它,因此它不能为空。

WebDriver driver = new WebDriver(some parameters here if any);