I've been trying to save an image on my local website, but most of the code examples I find are for C# and Java, which I am struggling to convert to JavaScript.
Many of the examples I come across use libraries like Point
and IO
that are not available in JavaScript. I even tried searching for code in Node.js on Stackoverflow, but the solutions I found didn't work for me.
Currently, my code can take a screenshot of the entire webpage, but what I really need is to capture an image with a specific ID. Here's the code I have so far:
driver.findElement(webdriver.By.xpath('//img[@id="c_pages_Image"]'))
.then(function(){
driver.takeScreenshot("c:\\selenium_local_map\\out1.png");
});
driver.takeScreenshot().then(function(data){
var base64Data = data.replace(/^data:image\/png;base64,/,"")
fs.writeFile("out.png", base64Data, 'base64', function(err) {
if(err) console.log(err);
});
});