question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Selector playground doesn't correctly escape period in id

See original GitHub issue

Current behavior:

When using the selector playground on an element (select or input in my case). The selected element it has a name attribute and an id attribute. Both attributes have a periods in them, like id="form.name.last". The code shown and copied to clipboard from the selector playground is incorrect.

This is what gets shown and copied to the clipboard:

Screenshot - 2019-04-06 , 11_02_37 AM

cy.get('#form\.name\.last')

JavaScript is treating this as if the period is being escaping and not passing the slash (\) through to Cypress. Thus the above is equivalent to this:

cy.get('#form.name.last')

When the test runs, the selector doesn’t work:

CypressError: Timed out retrying: Expected to find element: '#form.name.last', but never found it.

Desired behavior:

To get the slash (\) passed through to Cypress, then the slash itself needs escaped:

cy.get('#form\\.name\\.last')

Note the two slashes (\\). The tests work correctly with the slash being properly escaped.

However typing that into the selector playground shows an red error and the “Print to console” button is grayed out, so fixing that that would be part of what needs fixed:

Screenshot - 2019-04-06 , 10_58_34 AM

Versions

Cypress 3.2.0 Chrome 72

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
vladtheimpalacommented, Aug 21, 2020

Do we have general issues about id selector shorthand and some special chars ?

Template : <button id="product-add">

Not working :

.get('button#product-add')
.get('button#product\-add')

Working :

.get('button[id=product-add]')

Using an underscore char works perfectly with shorthand.

Cypress version : 5.0.0 Electron 83 / Chrome 84

0reactions
Schrankcommented, Dec 1, 2022

Same for [] as in id="group[6][15]"

IS: cy.get('#group\[7\]\[18\]') SHOULD BE: cy.get('#group\\[7\\]\\[18\\]')

But I understand the argument, that it is normal JS behaviour. But as long as I should be able to just copy from the selector, the selector should be copy pasteable and work.

I’m very thankful for cypress and it is an awesome tool! But I don’t have any doubt, this is a bug and should be fixed for better developer experience 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

CSS selector with period in ID - html
After digging through the specs some more, I found the CSS spec does allow for backslash ( \ ) escaping like most languages....
Read more >
Xcode 14 Release Notes | Apple Developer Documentation
Xcode 14 cannot be used with iOS 15.7 for development. ... Convert to Regex Builder doesn't correctly handle patterns with Unicode escape sequences....
Read more >
Commercial Driver License Manual
documents and at least one must reflect the date of birth. The documents cannot come from the same category (e.g. two school documents)....
Read more >
Greedy and lazy quantifiers
The regexp engine adds to the match as many characters as it can for .+ , and then shortens that one by one,...
Read more >
get
Get one or more DOM elements by selector or alias. ... Syntax Usage Correct. ... Find the element with id that has characters...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found