public String saveScreenshot ( String filename , long timeout , boolean includeImage , List < String > hashes ) { assertElementNotStale ( ) ; Canvas canvas = buildCanvas ( ) ; ScreenCaptureReply reply = exec . screenWatcher ( canvas , timeout , includeImage , hashes ) ; if ( includeImage && reply . getPng ( ) != null ) { FileChannel stream ; try { stream = new FileOutputStream ( filename ) . getChannel ( ) ; stream . write ( ByteBuffer . wrap ( reply . getPng ( ) ) ) ; stream . close ( ) ; } catch ( IOException e ) { throw new WebDriverException ( "Failed to write file: " + e . getMessage ( ) , e ) ; } } return reply . getMd5 ( ) ; }
Take a screenshot of the area this element covers . If the hash of the image matches any of the given hashes then no image is saved otherwise it saves a copy of the image to the given filename .