Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Screen shot of an element is white. #298

Open
AbhinayNegi opened this issue May 10, 2022 · 1 comment
Open

Screen shot of an element is white. #298

AbhinayNegi opened this issue May 10, 2022 · 1 comment

Comments

@AbhinayNegi
Copy link

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.:
image

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

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:
image

@Kavabungoz
Copy link

Kavabungoz commented Apr 6, 2023

I solved this problem. This is because of Scale settings in Windows.
You should open Display settings -> Scale and layout -> reset to 100% .
Let me know if these steps have helped you :)

You can also multiply the coordinate values by the percentage of monitor scaling.
For example: if the scale is 175%, then @param monitorScale = 1.75
.getSubimage((int) (point.getX()*monitorScale ), (int) (point.getY()*monitorScale ), (int) (elemWidth*monitorScale ), (int) (elemHeight*monitorScale ))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants