See example below.
1. Use selenium webdriver executeScript to inject script js first a plugin html2canvas in the html page you are testing
2. Then initiate the html2canvas callback to add a canvas into the html page document.body
3. Once done, access the canvas and use toDataUrl and create image element, you should be able to get the base64 image.
4. After that just accceses the image html element and write the base64 data into your file.
5. Lastly , don’t forget to remove the created/generated canvas and image element.