-
-
Notifications
You must be signed in to change notification settings - Fork 80
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
Selecting elements for screenshotting based on tag content #43
Comments
This is an interesting idea. Right now there is a workaround for this, but it's pretty messy. You can use JavaScript to assign an additional class to an element, then take a screenshot of that:
Running that now gets me this: |
I'm trying to think of a syntactically elegant way to support this. One way would be to support a fragment of JavaScript which is executed against every element on the page - so you would do this:
And it would effectively run the equivalent of my code above, except filtering against the list of elements returned by That could actually work pretty well. |
Would |
Alternative names for this option:
I'm not completely convinced by any of those yet. |
As a reminder, the current options for the
|
I don't like |
Oh hang on...
We already have a precedent for |
Or |
I think I've talked myself around to your original suggestion of |
If it's returning the first match it can use
|
TBH, your original work-around isn't that clunky.. it's really elegant in how it riffs on what's currently available, feature wise |
It'd require some reworking of a couple pieces of There could of course be an
Then you could just use Relevant Playwright client code: |
OK, I built a protoype. @psychemedia you can try it out by running:
Here's a demo:
Which produced this image (of the first paragraph on the page to contain the term Note that I had to include The demo also currently outputs debug info showing the JavaScript it generated - I'd remove that before shipping the feature:
|
Ah, wonderful.. will look for something to try it out on... |
I notice that you need to uppercase the tagname? |
Sort of thing you could easily weave into a twitterbot.. |
The thing that's holding me off from merging this right now is that it's got me thinking about the multiple element case. In trying this out I found myself wanting the ability to say "take a screenshot that incorporates all of the matching elements on the page" - where this mechanism currently filters for just the first match (using shot-scraper/shot_scraper/cli.py Lines 656 to 658 in 8a61c7e
This then made me think that I actually want the same ability for just raw CSS selectors. But what should that look like? |
I implemented
The obvious complement to the new
I was worried that it wouldn't make sense because there's no equivalent to the So I think the answer here is a |
Manual testing (with debug output):
|
Selecting elements as the target for screenshots based on CSS selectors does not (currently) allow for the selection of elements based on tag content, or relative to DOM elements selected based on tag content.
However, elements can be selected based on tag content using Javascript. It would be useful to allow for the selection of elements via Javascript as well as CSS.
Alternatively, support a method that can be called from a
javascript
scraper call that will apply a screen shot to a Javascript selected element.At the moment, selector based screenshots seem to be focused in
_selector_javascript(selectors)
by:shot-scraper/shot_scraper/cli.py
Line 520 in e40070d
As well as passing
--selector
(s),s
, one approach might be to pass element(s)el
returned from a--js-selector
script?The text was updated successfully, but these errors were encountered: