When attempting to do an assertion with the total of a dynamic table, I am encountering difficulties writing XPath that works for all scenarios. The issue arises because the table sometimes contains only 1 image and other times it may contain 5 images.
In the provided example, I have successfully used the following XPath: enter image description here WebElement totalElement = driver.findElement(By.xpath("//*[@id='image_table']/tbody/tr[5]/td[4]")); However, this XPath fails when the size of the table changes.
Below is the design of the webpage for reference:
<table class="table table-bordered table-striped table-hover display" id="image_table">
<tr>
<td colspan="2" class="text-right">Total</td>
<td class="text-center">1,650</td>
<td class="text-center">19,936</td>
<td class="text-center">21,586</td> (attempting to write xpath for this total)
</tr>