[🐛 Bug]: Wrong screenshot is generated for elements within iframes
See original GitHub issueWhat happened?
I am trying to take a screenshot of an element within an iframe using both TakesScreenshot and AShot classes upon switching to that certain iframe and I receive a wrong screenshot which is not of that element.
How can we reproduce the issue?
1. Have either Chrome 98.0.4758.82 or Microsoft Edge 98.0.1108.43 installed
2. Execute the following code on any website that has elements within an iframe (used http://demo.automationtesting.in/Frames.html for this test):
TakesScreenshot:
String currentUserDirectory = System.getProperty("user.home");
File screenshot = ((TakesScreenshot) getWebDriver()).getScreenshotAs(OutputType.FILE);
BufferedImage fullImg = ImageIO.read(screenshot);
Point point = element.getLocation();
setElementWidth(element.getSize().getWidth());
setElementHeight(element.getSize().getHeight());
BufferedImage elementScreenshot = fullImg.getSubimage(point.getX(), point.getY(), elementWidth, elementHeight);
ImageIO.write(elementScreenshot, "png", screenshot);
File screenshotPath = new File(currentUserDirectory + "\\Desktop\\" + " " + screenshotName);
FileUtils.copyFile(screenshot, screenshotPath);
Test class method:
TakeScreenshot takeScreenshot = new TakeScreenshot(getWebDriver());
TakeScreenshot takeScreenshot = new TakeScreenshot(getWebDriver());
Thread.sleep(2000);
getWebDriver().switchTo().frame(singleFrame);
testElement.sendKeys("test");
takeScreenshot.elementScreenshot(testElement, "TestElementTakesScreenshot.png"); // TakesScreenshot method
Relevant log output
No issues are received in the console.
Operating System
Windows 11
Selenium version
Java 4.1.2
What are the browser(s) and version(s) where you see this issue?
Chrome 98.0.4758.82 & Microsoft Edge 98.0.1108.43
What are the browser driver(s) and version(s) where you see this issue?
ChromeDriver 98.0.4758.80 & EdgeDriver 98.0.1108.43
Are you using Selenium Grid?
N/A
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Unable to take screenshot in Iframe - angular - Stack Overflow
I have created an example stackblitz demo here. Please help me, what I am doing wrong here. What is the other way to...
Read more >The ultimate guide to iframes - LogRocket Blog
Not a fan of iframes? This post provides an overview of the tag's best features, shows you how to use them, and how...
Read more >[New Plugin]: Screenshot Element Pro - Bubble Forum
We are excited to announce the launch of the Bubble plugin, Screenshot Element Pro! FEATURES: Generate screenshot of an Element by its ID ......
Read more >Working with iframes — Firefox Source Docs documentation
Note that the button is only displayed if the page includes iframes! Screenshot showing how to set an iframe as the target of...
Read more >Advanced iFrame – WordPress plugin
Include content the way YOU like in an iframe that can hide and modify elements, does auto height, forward parameters and does many,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You can just use the method on the element itself:
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.