Reputation: 2402
I am trying to get cell text by corresponding cell.
Column 1 Column 2
Deadline 02 Jul 2020
So by finding "Deadline" I need to get the date.
Here is HTML:
I am trying to use:
var MDeadline = driver.FindElement(By.XPath("//tr[./th[text()='Deadline']]/../td[1]"));
without success. What would be the right XPath?
Deadline:
Full XPath:
/html/body/section/div/div/div/div[1]/div[1]/div[3]/div/div[2]/div/div/table/tbody/tr[7]/th
XPath:
//*[@id="advsearchformdiv"]/tbody/tr[7]/th
Date:
Full XPath:
/html/body/section/div/div/div/div[1]/div[1]/div[3]/div/div[2]/div/div/table/tbody/tr[7]/td
XPath:
//*[@id="advsearchformdiv"]/tbody/tr[7]/td
Sometimes it is tr[6]
, sometimes tr[7]
that's why I need to stick logic to word "Deadline" without using full XPath.
Upvotes: 0
Views: 24
Reputation: 33384
Try below xpath options
Here since you are referring row you just need to select td tag
under that row.
var MDeadline = driver.FindElement(By.XPath("//tr[./th[text()='Deadline']]/td"));
OR select hearder tag and following-sibling::td
of that header tag
var MDeadline = driver.FindElement(By.XPath("//th[text()='Deadline']/following-sibling::td"));
Upvotes: 2