'Selenium AShot: Why Screen shot of an particular element is white
On this webpage: https://www.selenium.dev/downloads/
I am trying to capture the screenshot of an element that is an img tag.
You can inspect : img[alt='Java']
This is the img element I want to capture: Element to capture
So to capture the above element I wrote this code:
WebElement imgJava = driver.findElement(By.cssSelector("img[alt='Java']"));
Screenshot screenshotJava = new AShot().shootingStrategy(ShootingStrategies.viewportPasting(100)).takeScreenshot(driver, imgJava);
ImageIO.write(screenshotJava.getImage(), "png",new File(System.getProperty("user.dir") + "\\javaImg.png"));
But when I opened the image, it is just all white: Image after caputring
And if I remove the shooting shotingStrategy and just use new AShot().takeScreenshot(driver,imgJava);
It will take screenshot of whole page even though I passed a particular element:
Whole page
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
