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

[BUG] locator.count: Error while parsing selector ":nth-last-child(1 of ...) ~ *" #27743

Closed
1 task done
goodwin64 opened this issue Oct 22, 2023 · 2 comments · Fixed by #27841
Closed
1 task done

[BUG] locator.count: Error while parsing selector ":nth-last-child(1 of ...) ~ *" #27743

goodwin64 opened this issue Oct 22, 2023 · 2 comments · Fixed by #27841
Assignees
Labels

Comments

@goodwin64
Copy link

Maybe it's not the bug but not yet supported selector by Playwright so sorry in advance 🙏
I skimmed through the Stack Overflow and a couple of articles but couldn't find a similar issue.

System info

  • Playwright Version: [v1.XX] - default in playground
  • Operating System: [All, Windows 11, Ubuntu 20, macOS 13.2, etc.] - MacOS 14, but ran in the playground
  • Browser: [All, Chromium, Firefox, WebKit] - Chrome
  • Other info:

Source code

  • I provided exact source code that allows reproducing the issue locally.

Link to the test file

https://try.playwright.tech/?l=javascript&s=khc2kb8

Link to the JSFiddle with CSS selector usage
https://jsfiddle.net/654t7skb/9/

Steps

  • Open the JSFiddle, see that selector successfully highlights some elements
  • Run the Playwright playground file, see that it throws an error after being unable to parse that selector

Expected

nth-last-child( ) selector is supported

Actual

nth-last-child( ) selector is NOT supported

@goodwin64
Copy link
Author

Workaround I used instead:

// not working:
const nextElementsCount = await page
  .locator(':nth-last-child(1 of .Checkpoints:has(.Checkpoints_span).CheckpointCurrent2_Sign) ~ *')
  .count();

// working:
const nextElementsCount = await page.evaluate(
    () =>
      [
        ...document.querySelectorAll(
          ':nth-last-child(1 of .Checkpoints:has(.Checkpoints_span).CheckpointCurrent2_Sign) ~ *'
        ),
      ].length
  );

@yury-s yury-s added the v1.40 label Oct 24, 2023
dgozman added a commit that referenced this issue Oct 27, 2023
Things like `:nth-child(1 of :has(span:nth-last-child(3)))`.

Fixes #27743.
@goodwin64
Copy link
Author

Thank you! 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants