vendredi 3 avril 2020

Cypress : Getting an element from a table using another element as reference

ok, so here is the situation. I have a webpage where I add elements to a table, and when I add that element , the webpage automatically assign a number for it.

My question is: How can I get that number ? Because its automatically generated, so I have no way of knowing which number its going to be. The tables is something like that:

Name Number
Orange 35
Apple 452
Lemon 77

And the code :

<tr data-id="77">
                    <td class="col col-md-5 text-left">
                        Lemon
                    </td>
                    <td class="col col-md-5 text-left">
                        77
                    </td>
</tr>

as you can see, the number 77 does not have a unique identifier and when I created Lemon, I have no way of knowing what that number would be.

My first idea was to get the element on the left, which is Lemon, because I know its name (its me who gives its name, using .type() and then try and getting the element to the right of Lemon, which will be a number that I have no idea what number its going to be.

Is that possible? Is there a better way to do it ?

Aucun commentaire:

Enregistrer un commentaire