I am writing a selenium test to test a crud application where you can add, update, or delete a user. I have a table that dynamically displays all of the fields. When I add a new user, a new edit button is also added and when clicked edits that particular user. When trying to test this with selenium, I am not sure how to edit a specific user. I would like to edit the 4th user in the list, which would be index 3. I tried this,
var edit = wait.Until((d) => d.FindElements(By.Id("edit")));
edit[3].Click();
but get an index out of range error. If I do this:
var edit = wait.Until((d) => d.FindElement(By.Id("edit")));
edit.Click();
It allows me to edit the first person in the table.
<tr>
<td>Ray Peterson</td>
<td>deleted_0_rpeterson@aol.com</td>
<td>Developer</td>
<td>
<div class="pointer">
<div class="sprk-o-Stack sprk-o-Stack--split@xs" data-id="">
<div class="sprk-o-Stack__item sprk-o-Stack__item--half@xs sprk-o-Box" data-id="">
<div class="updateUser">
<svg class="sprk-c-Icon sprk-c-Icon--l" viewBox="0 0 64 64" data-id="" id="edit">
<use xlink:href="#editable"></use>
</svg>
</div>
</div>
<div class="sprk-o-Stack__item sprk-o-Stack__item--half@xs sprk-o-Box" data-id="">
<svg class="sprk-c-Icon sprk-c-Icon--l" viewBox="0 0 64 64" data-id="" id="deleted_0_rpeterson@aol.com">
<use xlink:href="#trash"></use>
</svg>
</div>
</div>
</div>
</td>
</tr>
<tr>
<td>Fredo Corleone</td>
<td>godfather88@gmail.com</td>
<td>Developer</td>
<td>
<div class="pointer">
<div class="sprk-o-Stack sprk-o-Stack--split@xs" data-id="">
<div class="sprk-o-Stack__item sprk-o-Stack__item--half@xs sprk-o-Box" data-id="">
<div class="updateUser">
<svg class="sprk-c-Icon sprk-c-Icon--l" viewBox="0 0 64 64" data-id="" id="edit">
<use xlink:href="#editable"></use>
</svg>
</div>
</div>
<div class="sprk-o-Stack__item sprk-o-Stack__item--half@xs sprk-o-Box" data-id="">
<svg class="sprk-c-Icon sprk-c-Icon--l" viewBox="0 0 64 64" data-id="" id="godfather88@gmail.com">
<use xlink:href="#trash"></use>
</svg>
</div>
</div>
</div>
</td>
</tr>
<tr>
<td>Try Again</td>
<td>tryagain@gmail.com</td>
<td>Developer</td>
<td>
<div class="pointer">
<div class="sprk-o-Stack sprk-o-Stack--split@xs" data-id="">
<div class="sprk-o-Stack__item sprk-o-Stack__item--half@xs sprk-o-Box" data-id="">
<div class="updateUser">
<svg class="sprk-c-Icon sprk-c-Icon--l" viewBox="0 0 64 64" data-id="" id="edit">
<use xlink:href="#editable"></use>
</svg>
</div>
</div>
<div class="sprk-o-Stack__item sprk-o-Stack__item--half@xs sprk-o-Box" data-id="">
<svg class="sprk-c-Icon sprk-c-Icon--l" viewBox="0 0 64 64" data-id="" id="tryagain@gmail.com">
<use xlink:href="#trash"></use>
</svg>
</div>
</div>
</div>
</td>
</tr>