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] Issue with chained selectors -- text selector doesn't work #4865

Closed
jmtoung opened this issue Jan 1, 2021 · 3 comments
Closed

[BUG] Issue with chained selectors -- text selector doesn't work #4865

jmtoung opened this issue Jan 1, 2021 · 3 comments
Assignees

Comments

@jmtoung
Copy link

jmtoung commented Jan 1, 2021

Context:

  • Playwright Version: "@playwright/test": "^0.162.0"
  • Operating System: [e.g. Windows, Linux or Mac]
  • Node.js version: [e.g. 10.12, 10.14]
  • Browser: [e.g. All, Chromium, Firefox, WebKit]
  • Extra: [any specific details about your environment]

Describe the bug

When I use chained selectors, I observe the following behavior. Not sure if this is intended or what.

await page.click('div[role="radiogroup"] >> "No"') // DOES NOT WORK, I expect it to work though.
await page.click('div[role="radiogroup"] >> No') // DOES NOT WORK. This is expected since the `text=` engine is only inferred for double quoted text.

await page.click('div[role="radiogroup"] >> text="No"') // DOES NOT WORK, I expect it to work though.
await page.click('div[role="radiogroup"] >> text=No') // WORKS

I have attached a screenshot of my DOM.

Screen Shot 2021-01-02 at 6 18 39 AM

@dgozman
Copy link
Contributor

dgozman commented Jan 4, 2021

Could you please try printing element's text content? I expect that your target element has line breaks, and therefore "No" that performs strict equality check does not match. You can read about quoted vs unquoted text selectors in the docs.

console.log(await page.textContent('div[role="radiogroup"] >> text=No'))

Also note that 'div[role="radiogroup"] >> No' will not work because it expects the text= qualifier before No. We only infer text selector for quoted text. You can read more about selector short forms in the docs. There should be a useful error message in this case, is it missing?

@jmtoung
Copy link
Author

jmtoung commented Jan 4, 2021

Thank you @dgozman for the quick response.

  1. You are right! As you can see in my screenshot, the 'No' radio button we want to select is wrapped in a div (<div>No</div>) but for some reason, it adds a white space after the text, which is why it wasn't working.
  2. I updated my original post, you are right, the selector 'div[role="radiogroup"] >> No' should not work.
  3. It seems that await page.click('div[role="radiogroup"] >> text=No') works because it is not case sensitive. Is this to be expected? In other words, when you have text=value and value is not quoted, the resulting match is not case sensitive?
  4. I didn't see a useful error message

Screen Shot 2021-01-05 at 7 39 29 AM

await page.click('div[role="radiogroup"] >> "No"') // DOES NOT WORK, I expect it to work though -- TURNS OUT REASON IT DIDNT WORK IS BECAUSE WE HAD AN EXTRA WHITE SPACE.
await page.click('div[role="radiogroup"] >> No') // DOES NOT WORK. This is expected since the `text=` engine is only inferred for double quoted text.

await page.click('div[role="radiogroup"] >> text="No"') // DOES NOT WORK, I expect it to work though.
await page.click('div[role="radiogroup"] >> text=No') // WORKS

@dgozman
Copy link
Contributor

dgozman commented Jan 4, 2021

await page.click('div[role="radiogroup"] >> text="No"') // DOES NOT WORK, I expect it to work though.

I do not expect this snippet to work, because it requires strict match while text has whitespace inside.

It seems that await page.click('div[role="radiogroup"] >> text=No') works because it is not case sensitive. Is this to be expected? In other words, when you have text=value and value is not quoted, the resulting match is not case sensitive?

Yes, it works because matching without quotes is relaxed. Quoting the docs: "By default, the match is case-insensitive, ignores leading/trailing whitespace and searches for a substring".

@jmtoung jmtoung closed this as completed Jan 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants