xpath to locate a table data cell based on a condition of another cell in the same row

147 views
Skip to first unread message

Zhang Zhao

unread,
Jan 28, 2022, 7:56:16 PM1/28/22
to Selenium Users
Hi, Is there a way to locate a particular table data cell element based on a condition from another cell in the same row by XPath? I was able to locate the conditional cell by Xpath (//td[@role=“gridcell”]//span[@title=“Professional”])[1]. However, I am not sure how do I locate the target cell in the same row based on the result of the condition. The goal is to locate&click the anchor element in the target table header in a condition of title=professional from the other cell in the same row.

<table> ... <tbody> <tr>..</tr> <tr>..</tr> ... <tr> <td>..</td> <th> <span class="xxx"> <a class="yyy" title="my_title">..</a> </span> </th> <td role="gridcell"> <span class="abc"> <span title="Professional">Professional</span> </span> </td> <td>..</td> </tr> ... </tbody> </table>




Zhang

joseph...@gmail.com

unread,
Feb 2, 2022, 6:51:55 PM2/2/22
to Selenium Users
I put your html snippet into an html file on my computer, then used the dev tools to test out an xpath.  This is the xpath within the dev tools $x() function for testing it that returned me the a element.

$x("//td[@role='gridcell']//span[@title='Professional'][1]//preceding::th//a")

Here's some information about XPath Axes that might be helpful to you.

Reply all
Reply to author
Forward
0 new messages