I'm trying to get the index of a <tr>
element based on the contents of its <td>
elements in Selenium using xpath.
String xpath = "count(//tr[td[text()='Column Value A'] and td[text()='Column Value B']]/preceding-sibling::*)"
WebElement count = driver.findElement(By.xpath(xpath))
However, I'm getting this exception.
org.openqa.selenium.InvalidSelectorException: invalid selector: Unable to locate an element with the xpath expression count(//tr[td[text()='Column Value A'] and td[text()='Column Value B']]/preceding-sibling::*) because of the following error:
TypeError: Failed to execute 'evaluate' on 'Document': The result is not a node set, and therefore cannot be converted to the desired type.
Is there any way for Selenium to return the value of an aggregate xpath function?
Thanks in advance for your help!