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

selector should always prefer ID tags over classes #32

Closed
tnolet opened this issue Oct 14, 2018 · 1 comment · Fixed by #50
Closed

selector should always prefer ID tags over classes #32

tnolet opened this issue Oct 14, 2018 · 1 comment · Fixed by #50
Assignees
Labels
🦾 enhancement New feature or request
Milestone

Comments

@tnolet
Copy link
Member

tnolet commented Oct 14, 2018

currently, this is possible. A bunch of generated classes with a perfectly fine ID tag at the end. In these cases, the ID tag should "win" and the class selectors disregarded.

  await page.waitForSelector('.loCvjm > .dqCcvp > .iczaPt > .hkOTKM > #ListingSort--SortPicker')
  await page.click('.loCvjm > .dqCcvp > .iczaPt > .hkOTKM > #ListingSort--SortPicker')
@tnolet tnolet added the 🦾 enhancement New feature or request label Oct 14, 2018
@tnolet tnolet changed the title selector should always prefer ID tags over classes tags selector should always prefer ID tags over classses Oct 14, 2018
@tnolet tnolet changed the title selector should always prefer ID tags over classses selector should always prefer ID tags over classes Oct 14, 2018
@tnolet tnolet self-assigned this Oct 14, 2018
@rationalthinker1
Copy link
Contributor

rationalthinker1 commented Apr 16, 2019

I am thinking something like this:

const optimizedMinLength = (e.target.id) ? 2 : 10
const selector = this.dataAttribute && e.target.hasAttribute && e.target.hasAttribute(this.dataAttribute)
        ? formatDataSelector(e.target, this.dataAttribute)
        : finder(e.target, {seedMinLength: 5, optimizedMinLength: optimizedMinLength})

Basically, it the target element has an id, make the minimal length small to 2 and otherwise, make it 10. Although I think that it should always be 2, but I don't know whether the finder will uniquely select that element or not.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🦾 enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants