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

Element screenshots incorrect when page has been scrolled #76

Open
jorenko opened this issue Apr 19, 2018 · 0 comments
Open

Element screenshots incorrect when page has been scrolled #76

jorenko opened this issue Apr 19, 2018 · 0 comments

Comments

@jorenko
Copy link

jorenko commented Apr 19, 2018

When the page has been scrolled, the element coordinates returned by NeedleWebElementMixin.get_dimensions() are relative to the top-left of the page, but the screenshot that get_screenshot() crops starts at the current scroll position. This results in the returned screenshot being of either the wrong part of the page or mostly/all blank, depending on the browser. To fix this, the current scroll position needs to be subtracted from the position, like so:

diff --git a/home/jjurack/.local/share/virtualenvs/test_web-6ViYfjms/lib/python3.6/site-packages/needle/driver-orig.py b/home/jjurack/.local/share/virtualenvs/test_web-6ViYfjms/lib/python3.6/site-packages/needle/driver.py
index cd10b49..eceafe5 100644
--- a/home/jjurack/.local/share/virtualenvs/test_web-6ViYfjms/lib/python3.6/site-packages/needle/driver-orig.py
+++ b/home/jjurack/.local/share/virtualenvs/test_web-6ViYfjms/lib/python3.6/site-packages/needle/driver.py
@@ -63,8 +63,8 @@ class NeedleWebElementMixin(object):
         d = self.get_dimensions()
         
         # Cast values to int in order for _ImageCrop not to break
-        d['left'] = int(d['left'])
-        d['top'] = int(d['top'])
+        d['left'] = int(d['left']) - self._parent.execute_script('return window.scrollX')
+        d['top'] = int(d['top']) - self._parent.execute_script('return window.scrollY')
         d['width'] = int(d['width'])
         d['height'] = int(d['height'])
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

1 participant