I want to save 1 image in my local website. I'll research all internet, I find almost is C# and Java code but I can't convert it to Javascrip.
Almost example using Point
, IO
library is not available in javascript. I also search code in nodejs in Stackoverflow . I've was test but it not working for me.
Present, My code can Takescreenshot
all webpage but I want it capture image with id. Here is code:
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);
});
});
let imageElement = await driver.wait(until.elementLocated(By.xpath('//img')), 5000) // returns image element
let screenshot = await imageElement.takeScreenshot(false) // takes screenshot of image element
fs.writeFileSync('\path\to\target\file', screenshot, 'base64')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.