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

snap() not working? - captures whole page instead of web element [fixed] #7

Closed
brandybaby opened this issue Jun 21, 2019 · 7 comments
Closed
Labels

Comments

@brandybaby
Copy link

Hi! I was hoping to use TagUI to automate generating of a .png image, as part of a small personal project. This is done through a website:

https://www.myfakeinfo.com/nationalidno/get-china-citizenidandphoto.

As I attempted to take a snapshot of the image generated, using t.snap('log1','front.png'), where 'log1' is the element id, ''front.png' is the intended saved image. However, this action takes a screenshot of the whole webpage, instead of just saving the image.

I was just wondering if this is your intended output, and could there be anyway I can use TagUI API to carry out saving image?

Thanks!

@kensoh kensoh added the query label Jun 21, 2019
@kensoh
Copy link
Member

kensoh commented Jun 21, 2019

Hi @brandybaby thanks for raising this!

The expected behaviour should be taking screenshot of the web element only and not the whole webpage. After checking, this looks like a bug in the upstream project TagUI. I'll raise an issue there and follow-up. It could be due to change in Chrome browser behaviour in newer versions or some other reasons. Which causes the screenshot to be entire webpage instead of only the element.


Minimum replication case - below works in TagUI normal mode but does not work in live mode.

https://google.com
snap //*[@name="q"] to q.png

@kensoh kensoh added bug and removed query labels Jun 21, 2019
@kensoh kensoh changed the title snap() not functioning properly? snap() not functioning properly? - captures whole page instead of web element Jun 21, 2019
@kensoh
Copy link
Member

kensoh commented Jun 21, 2019

Fix implemented upstream, try doing t.setup() and see if it now works for you.

kensoh added a commit that referenced this issue Jun 22, 2019
#6 - on macOS with Python 3, there is no SSL certs support by default. adding an additional check to auto-install SSL certs. before this change, download() simply fails.

#7 - adding capability to autosync tagui delta files when new tagui for python releases are installed. this lets users immediately access current features when they do a pip install tagui --upgrade. before this change, t.setup() is needed for existing installations.

#7 - upstream fix implemented for snapshots of web elements on Chrome. fix improves performance and quality base on newer DevTools Protocol capabilities. the fix is accessible when users do a pip install tagui --upgrade. before this change, snap() captures screenshot of the whole webpage instead of only the element.
@kensoh
Copy link
Member

kensoh commented Jun 22, 2019

Made a commit with below comments. pip install tagui --upgrade or new installations should now work. Commit will autosync delta files for new releases of TagUI for Python, even if there is an existing installation. Prior to this, users need to do t.setup() to force re-installation of TagUI.

#6 - on macOS with Python 3, there is no SSL certs support by default. adding an additional check to auto-install SSL certs. before this change, download() simply fails.

#7 - adding capability to autosync tagui delta files when new tagui for python releases are installed. this lets users immediately access current features when they do a pip install tagui --upgrade. before this change, t.setup() is needed for existing installations.

#7 - upstream fix implemented for snapshots of web elements on Chrome. fix improves performance and quality base on newer DevTools Protocol capabilities. the fix is accessible when users do a pip install tagui --upgrade. before this change, snap() captures screenshot of the whole webpage instead of only the element.

@kensoh kensoh changed the title snap() not functioning properly? - captures whole page instead of web element snap() not working properly? - captures whole page instead of web element [fixed] Jun 22, 2019
@kensoh kensoh changed the title snap() not working properly? - captures whole page instead of web element [fixed] snap() not working? - captures whole page instead of web element [fixed] Jun 22, 2019
@kensoh
Copy link
Member

kensoh commented Jun 25, 2019

Adding an observation that Chrome taking snapshots in this new way (capturing clipped region vs whole page and clip) momentarily show just the clipped area on the webpage, and showing blank on rest of page. After snapshot is done, it shows back the full webpage. This behaviour is a little unexpected.

Would think either not blanking rest of page, or blanking rest of page while retaining the clipped region, instead of bringing to top left of window. Looking forward to more data points from other users and perhaps other developers on this Chrome behaviour.

@brandybaby
Copy link
Author

Thanks for your help Ken! Will be testing this out now and update if there are any further issues.

@brandybaby
Copy link
Author

For my case, I found that the function snap() requires the full XPath. Tried the method of finding the exact location of my intended img src using XPath selector. The element_identifier I used is an XPath written in the form of id/name/class, and this worked for me!

@kensoh
Copy link
Member

kensoh commented Jun 28, 2019

Thanks for updating back here that it works now!

Yes while the tool supports below as identifiers, XPath is my personal recommended method because it is very expressive (including using and / or) and can do what CSS selectors cannot.

For web automation, web element identifier can be XPath selector, CSS selector or the following attributes - id, name, class, title, aria-label, text(), href (in decreasing order of priority)

Usually I pick an explicit XPath so that my script can fail fast, rather than assuming that everything is fine and working, and caught by surprise later that something broken gone undetected.

@kensoh kensoh closed this as completed Jun 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants