Home > Blockchain >  Attribute selector with quotes?
Attribute selector with quotes?

Time:08-17

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?

CodePudding user response:

You can escape the double quotes like this:

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

CodePudding user response:

Backticks are valid string delimeters

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