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]: aria/ queries don't support single-quote delimiters for role names #7721

Closed
andyearnshaw opened this issue Oct 25, 2021 · 4 comments
Closed
Assignees
Labels

Comments

@andyearnshaw
Copy link
Contributor

andyearnshaw commented Oct 25, 2021

Bug description

Steps to reproduce the problem:

  1. Open a page in Puppeteer with at least one element with role="region" attribute set
  2. Call page.$() with the following query: aria/[role='region']
  3. Observe that the result is null

Puppeteer version

v10.4.0

Node.js version

v16.12.0

npm version

v8.1.0

What operating system are you seeing the problem on?

Linux, macOS, Windows

Relevant log output

[17:34:32] › Error: waiting for selector `Format[role='tab']` failed: timeout 20000ms exceeded
xceeded
    at new WaitTask (/Users/andyearnshaw/Projects/dashvis/node_modules/.pnpm/puppeteer@5.5.0/node_modules/puppeteer/lib/cjs/puppeteer/common/DOMWorld.js:505:34)
    at DOMWorld.waitForSelectorInPage (/Users/andyearnshaw/Projects/dashvis/node_modules/.pnpm/puppeteer@5.5.0/node_modules/puppeteer/lib/cjs/puppeteer/common/DOMWorld.js:416:26)
    at Object.waitFor (/Users/andyearnshaw/Projects/dashvis/node_modules/.pnpm/puppeteer@5.5.0/node_modules/puppeteer/lib/cjs/puppeteer/common/AriaQueryHandler.js:62:21)
    at DOMWorld.waitForSelector (/Users/andyearnshaw/Projects/dashvis/node_modules/.pnpm/puppeteer@5.5.0/node_modules/puppeteer/lib/cjs/puppeteer/common/DOMWorld.js:312:29)
    at Frame.waitForSelector (/Users/andyearnshaw/Projects/dashvis/node_modules/.pnpm/puppeteer@5.5.0/node_modules/puppeteer/lib/cjs/puppeteer/common/FrameManager.js:842:51)
    at waitFor (/Users/andyearnshaw/Projects/dashvis/resources/e2e-core/framework/utils/interactions.js:90:30)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Object.ariaClick (/Users/andyearnshaw/Projects/dashvis/resources/e2e-core/framework/utils/interactions.js:270:20)
    at async worldConstructor.<anonymous> (/Users/andyearnshaw/Projects/dashvis/workspaces/report-page/e2e/features/support/steps/mouse.js:57:5)
    at async /Users/andyearnshaw/Projects/dashvis/resources/e2e-core/framework/createStepRunnerFactory.js:17:11
    at async worldConstructor.runStep (/Users/andyearnshaw/Projects/dashvis/resources/e2e-core/framework/createStepRunnerFactory.js:47:9)
@andyearnshaw
Copy link
Contributor Author

Note that, in the log output, I'm using a different selector and API function than the ones suggested in the repro steps. You can see in the source code for v10.4.0 that ' is not part of the attribute selector regex.

@johanbay
Copy link
Collaborator

johanbay commented Nov 4, 2021

I think it was a conscious decision to limit the API to just double quote delimiters to simplify the selector syntax a bit.
With that said, I am not opposed to extending it to support single quotes too.

@andyearnshaw
Copy link
Contributor Author

I think it's more an issue that they look similar to attribute selectors and a lot of people use " as their default string delimiters so flipping the "selector" to use single quotes might be the natural behaviour. That's at least what caused me to run into it, and the fact that it doesn't throw with a decent error message (at least in the waitFor case it was just "waiting for selector... timeout") made me spend more time exploring what the problem could be.

I could probably submit a PR today for this, since it's a pretty quick and easy fix.

andyearnshaw pushed a commit to andyearnshaw/puppeteer that referenced this issue Nov 5, 2021
This updates the regular expression used to parse aria attribute
selectors so that single quotes may be used as an alternative to double
quotes, e.g. `aria/Single button[role='button']`.

Issues: puppeteer#7721
johanbay pushed a commit that referenced this issue Nov 9, 2021
…#7750)

This updates the regular expression used to parse aria attribute
selectors so that single quotes may be used as an alternative to double
quotes, e.g. `aria/Single button[role='button']`.

Issues: #7721

Co-authored-by: Andy Earnshaw <andy.earnshaw@gmail.com>
@johanbay
Copy link
Collaborator

johanbay commented Nov 9, 2021

Closing this issue since the PR has now been merged.
Again, thank you for fixing this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment