admin管理员组文章数量:1431000
I have a list in a simple html file only with emails received and I want to access the last email in the list from a specific email address. I tried with last (), but it didn't work, it just doesn't lead me to the last item, but to one of the first items in the list
cy.contains('[email protected]').last().click()
An item in the list has the following code:
<br>
<a href="/Emails/2020-12-03%2016_40_54%20-%[email protected]">2020-12-03 16_40_54 - [email protected]</a>
I have a list in a simple html file only with emails received and I want to access the last email in the list from a specific email address. I tried with last (), but it didn't work, it just doesn't lead me to the last item, but to one of the first items in the list
cy.contains('[email protected]').last().click()
An item in the list has the following code:
<br>
<a href="/Emails/2020-12-03%2016_40_54%20-%[email protected]">2020-12-03 16_40_54 - [email protected]</a>
Share
Improve this question
edited Oct 10, 2021 at 16:30
Alex Cristian
asked Oct 10, 2021 at 15:46
Alex CristianAlex Cristian
472 silver badges4 bronze badges
4
-
is the email
[email protected]
unique in the list ? – Alapan Das Commented Oct 10, 2021 at 15:54 - "I tried with last (), but it didn't work" what does "it didn't work" mean? Share the error message. It's hard to guess. – pavelsaman Commented Oct 10, 2021 at 16:28
- No, it's not unique. It appears several times on the page. – Alex Cristian Commented Oct 10, 2021 at 16:29
- I have no error, it just doesn't lead me to the last item, but to one of the first items in the list – Alex Cristian Commented Oct 10, 2021 at 16:29
2 Answers
Reset to default 6It's a problem with Cypress, some mands "yield" many elements and some only one element.
You can check the the contains() - Yields section of the mand, this one only gives you one element, which will be the .first()
in the list.
.contains() yields the new DOM element it found.
IMO the docs should be more explicit. You learn to pick it up with experience, but can waste a lot of time trying to hack about with what looks like legit mands.
Try .get()
and .filter()
, using jQuery pseudo-selector :contains()
which return all matching elements
cy.get('a')
.filter(':contains([email protected])')
.last()
or add the pseudo-selector :contains()
inside the .get()
cy.get('a:contains([email protected])')
.last()
Assuming [email protected]
is unique and occurs once in your webpage, you write:
cy.contains('a', '[email protected]').click()
本文标签: javascriptCypress Accessing the last item in the listStack Overflow
版权声明:本文标题:javascript - Cypress: Accessing the last item in the list - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745472378a2659807.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论