2017-06-12 68 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);