Cypress Finding element by partial element name

Viewed 83

I would like to get this element in cypress tests but using only part of string without 'undefined'. How can I do that?

<line-chart-undefined tabindex="0"></line-chart-undefined>

1 Answers

It can be easily done with XPath.

  1. Install cypress-xpath plugin
  npm i -D cypress-xpath
  1. Then include in your project's cypress/support/index.js
  require('cypress-xpath')
  1. After installation your cy object will have xpath command
  cy.xpath("//*[starts-with(name(), 'line-chart-')]")

It'll find the element that matches the line-chart- tag

Related