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

Cannot take screenshot of document containing only absolutely-positioned elements #931

Open
juangj opened this issue Sep 7, 2017 · 6 comments

Comments

@juangj
Copy link
Contributor

juangj commented Sep 7, 2017

System

  • Version: 0.18.0
  • Platform: Linux
  • Firefox: 57.0a1 (2017-09-06) and 55.0 and 54.0 (probably everything Geckodriver supports)
  • Selenium: 3.4.0, but it shouldn't matter

Testcase

<div style="position: absolute; width: 200px; height: 200px; background-color: blue;"></div>
import sys

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

driver = webdriver.Remote(command_executor=sys.argv[1],
                          desired_capabilities=DesiredCapabilities.FIREFOX.copy())

driver.get('http://localhost/a.html')
s = driver.get_screenshot_as_base64()
print('%s (%d bytes)' % (s, len(s)))
driver.quit()

Output is iVBORw0KGgoAAAANSUhEUgAABQAAAAAICAYAAACmj1I9AAAAVUlEQVR4nO3YQQkAMAzAwPo33aoYg3CnIO/MAgAAAABZ8zsAAAAAAHjHAAQAAACAMAMQAAAAAMIMQAAAAAAIMwABAAAAIMwABAAAAIAwAxAAAAAAwg6DL2lSiZEF0gAAAABJRU5ErkJggg== (192 bytes), which is a 1280 x 8 PNG that is all white pixels. I expect the screenshot to contain, at a minimum, the 200x200 blue rectangle.

1280x8 is equal to the dimensions of document.documentElement.getBoundingClientRect(). And the spec does indeed say to screenshot the "current top-level browsing context’s document element’s rectangle". So this may technically be in line with the spec, but it's not a very desirable outcome.

FWIW, if you position the div at top: 0, then the div intersects the document's rectangle, so you can see some blue in the screenshot.

Trace-level log

geckodriver.log.txt

@juangj
Copy link
Contributor Author

juangj commented Sep 7, 2017

This is probably approximately equal to #465.

@whimboo
Copy link
Collaborator

whimboo commented Sep 8, 2017

Please note that @AutomatedTester raised bug 1398087 so that it is taken from the top-level browsing context.

@sawatsky
Copy link

I am encountering the same issue.

I need to take a screenshot of an element that contains a position: absolute descendant who is partially outside its ancestor's borders. As such, when I take the screenshot, the absolutely-positioned descendant is chopped in half.

By extension, the JavaScript function getBoundingClientRect() doesn't capture the descendant in its coordinates either, as @juangj noted.

@AndreyBelym
Copy link

Looks like it was fixed in Firefox 66.

@whimboo
Copy link
Collaborator

whimboo commented Sep 24, 2019

Looks like we missed to file a bug for Marionette. This is https://bugzilla.mozilla.org/show_bug.cgi?id=1581494 now.

@whimboo
Copy link
Collaborator

whimboo commented Sep 24, 2019

I just filed the webdriver issue for discussion: w3c/webdriver#1443

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

No branches or pull requests

4 participants