How to get count of all elements matching a locator and loop through them #21647
-
|
Hi, I'm finding nothing online to explain how to get the count of all elements that match a locator. For example, I have a locator: but none of these count, length or size functions exist in Cypress. What can I do in order to achieve this? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
|
You may want to read about cy.get("div.right-block > div.content_price > span.price").each($el => {
// code to iterate each element
} |
Beta Was this translation helpful? Give feedback.
-
|
@jjhelguero thanks for your answer but in my particular case, I don't think it's exactly what I need, as I need to use the index of the highest price dress to select a different element on that dress item. I ended up using: Although it's not in the code provided, I later use the dressCount index to click the name element of the dress with the highest price to view its details. |
Beta Was this translation helpful? Give feedback.
@jjhelguero thanks for your answer but in my particular case, I don't think it's exactly what I need, as I need to use the index of the highest price dress to select a different element on that dress item.
I ended up using: