Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

data-* not useful without looping through parent elements #52

Closed
tadeusgregorian opened this issue Apr 25, 2019 · 2 comments
Closed

data-* not useful without looping through parent elements #52

tadeusgregorian opened this issue Apr 25, 2019 · 2 comments
Milestone

Comments

@tadeusgregorian
Copy link

It would help a lot if, when checking for a data- attribute of an element, to also loop through parent html-elements. Because in most cases click events are triggered on nested elements of a UI framework.
So data-* attributes dont help a lot in this cases.

@tnolet
Copy link
Member

tnolet commented Jun 12, 2019

@tadeusgregorian please provide a more in depth example of what it is exactly that you propose.

@ephetic
Copy link
Contributor

ephetic commented Jul 12, 2019

@tnolet Right now the _dataAttribute only works if it is on the exact element you click on. Matching _dataAttributes on ancestors of an element are always ignored, thus my styled-component classes get used in the selector rather than my data-qa attribute that I can see on all of them.

I talking with @medv/finder about adding support for attributes, so right now it looks like the PR for puppeteer-recorder will be something like

--- a/src/content-scripts/EventRecorder.js
+++ b/src/content-scripts/EventRecorder.js
@@ -101,8 +101,8 @@ export default class EventRecorder {
     // for these events we cannot generate selectors, which is OK
     try {
       const optimizedMinLength = (e.target.id) ? 2 : 10 // if the target has an id, use that instead of multiple other selectors
-      const selector = this._dataAttribute && e.target.hasAttribute && e.target.hasAttribute(this._dataAttribute)
-        ? EventRecorder._formatDataSelector(e.target, this._dataAttribute)
+      const selector = this._dataAttribute
+        ? finder(e.target, {seedMinLength: 5, optimizedMinLength: optimizedMinLength, attr: (name, _value) => name === this._dataAttribute})
         : finder(e.target, {seedMinLength: 5, optimizedMinLength: optimizedMinLength})

so that the custom attributes will be used everywhere in the selector.

@ephetic ephetic mentioned this issue Jul 22, 2019
1 task
@tnolet tnolet added this to the v0.7.1 milestone Jul 30, 2019
@tnolet tnolet closed this as completed Jul 30, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants