Reputation: 381
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>
Upvotes: 2
Views: 780
Reputation: 202
Since cypress-xpath
is now deprecated, this is how you would do it with CSS selectors
cy.get('parent-element')
.children()
.filter((index, element) => element.tagName.startsWith('line-chart'))
Upvotes: 4
Reputation: 8690
It can be easily done with XPath.
npm i -D cypress-xpath
cypress/support/index.js
require('cypress-xpath')
cy
object will have xpath
command cy.xpath("//*[starts-with(name(), 'line-chart-')]")
It'll find the element that matches the line-chart-
tag
Upvotes: 1