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] Documentation in regards to text selector engine and single and double quotes #1982

Closed
thernstig opened this issue Apr 25, 2020 · 1 comment · Fixed by #2002
Closed

Comments

@thernstig
Copy link
Contributor

thernstig commented Apr 25, 2020

Context:

  • Playwright Version: 0.15.0

Describe the bug
#1952 introduced the concept that both single and double quotes to indicate a text selector. There are a few documentation errors now due to this:

  1. https://github.com/microsoft/playwright/blob/master/docs/api.md#working-with-selectors still only mentions double quotes "
  2. https://github.com/microsoft/playwright/blob/master/docs/selectors.md says:

Selector surrounded with quotes (either " or ') is assumed to be text=selector. Example: page.click('"foo"') is converted to page.click('text="foo"').

This is not correct because of the word surrounded. The actual " and ' is part of the selector. aslushnikov explained this here #1239 (comment):

Your change says:

Selector starting with " is assumed to be text=selector.

@thernstig I see what you mean and how it might be confusing. The definition is technically correct - double-quotes are a part of selector. Let me break down the example that we have in the docs:

  1. consider page.click('"foo"') (notice how there are single-quotes that wrap double-quotes)
  2. in this case, selector is "foo".
  3. selector starts with ", so it is transformed into the form of text=selector
  4. substituting selector with its value, getting text="foo"
  5. which gets us to page.click('text="foo"')

Does the explanation make things any better?

There are one of two possible ways to fix 2) above.

a) Either to update the docs.
b) Or as can be seen in that same thread, I suggest that ' and " is not included in the conversion. Reason I recommend the latter is due to that #1341 made the default for text=some text to match case-insensitive, substring matching. Essentially this is what I recommend makes more sense. Example: page.click('"foo"') and page.click("'foo'") is converted to page.click('text=foo'). This will then default to the best default for text selectors.

@dgozman
Copy link
Contributor

dgozman commented Apr 27, 2020

I am still hesitant to introduce the change proposed in (b). This would make text behave differently from css and xpath, and also break the mental model "quotes mean strict match".

Let me update the docs.

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

Successfully merging a pull request may close this issue.

2 participants