typescriptcss-selectorsattributescypress

Attribute selector with quotes?


So I'm trying to add a locator constant in my Cypress page objects and I have to use a locator that looks similar to this:

[ng-if="this.customThing.length > 1 && customThing.code !== 'widget.this.thing'"]

The problem is, when I try to wrap the whole thing in quotes in my TypeScript Cypress page object class such as:

LOCATOR_CONSTANT_VARIABLE = "[ng-if="this.customThing.length > 1 && customThing.code !== 'widget.this.thing'"]"

Obviously this won't work due to the multiple uses of quotes and single quotes won't work either.

What's the best way to escape the quotes to use in TypeScript for such an occasion?


Solution

  • You can escape the double quotes like this:

    LOCATOR_CONSTANT_VARIABLE =
      "[ng-if=\"this.customThing.length > 1 && customThing.code !== 'widget.this.thing'\"]";