There is a table with multiple rows.
I am locating an element of this table using sccSelector
WebElement myElement = driver.findElement(By.cssSelector...........);
This element belongs to some table row, let's say row 5. How can I get this row's number?
int myElementRowNumber = ???
Use rows = myElement.findElement(By.xpath("ancestor::table[1]"))
to locate the table. Then you can use table.findElements( By.xpath("./tbody/tr"))
to get all rows.
Use another row = myElement.findElement(By.xpath("ancestor::tr[1]"))
to get the row element.
Now it's simply:
int myElementRowNumber = rows.indexOf( row );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With