Reputation: 13
My HTML:
I have to extract td value which is "[email protected]"
when i do :
TemplatePage.getInvitaionPendingUser().each(($user, index, $list) => {
if($user.text('Invitation pending')){
userEmail = $user.innerText()
}
});
it gives me div text which is "Invitaion pending"
using cypress with typescript
Upvotes: 0
Views: 240
Reputation: 32158
You might be looking for $user.text().includes()
, depending on what element is $user
.
TemplatePage.getInvitaionPendingUser().each(($user, index, $list) => {
if ($user.text().includes('Invitation pending') {
userEmail = $user.innerText()
}
});
Upvotes: 0
Reputation: 5481
You can also use .contains()
on the whole <td>
cy.contains('td', 'Invitation pending') / checks the child div also!
.each($user => {
userEmail = $user.innerText()
})
Upvotes: 1
Reputation: 18574
You can do something like this:
cy.contains('Invitation pending')
.parent('td')
.invoke('text')
.then((text) => {
cy.log(text) //will print [email protected] and Invitation pending
})
You can then use JS methods like split to extract your text [email protected]. Or, you can add the log text what you are getting in the comments then I can edit the answer.
Upvotes: 1