Home > Enterprise >  Cypress. How to use variable as attribute value
Cypress. How to use variable as attribute value

Time:08-02

I have problem with using variables. To log I use:

var login = 'username';
...
cy.get('#username').type(login);

Then username is in here:

<li  title="username" ng-click="$ctrl.bocznyPanelInformacyjny.toggle()" ow-shortcut="user">

How to get that title with login value? In protractor i used:

this.Login = login;
element(by.css('li[title=' this.Login ']'))

In cypress I have Login undefined error. Tryed to google answer but no success.

CodePudding user response:

You have to use a String literal for this:

var login = 'username';
cy.get(`li[title='${login}']`)
  • Related