XPath for the whole table which has 11 rows :
$x(".//div[@id='less_detail']/table/tbody/tr/td[1]/table[1]/tbody[1]/tr[1]/td[1]/table/tbody/tr/td[1]")
Result:
The result was like this:
HTML Code:
<div id="less_detail"><table width="100%"><tbody><tr>
<td><table width="100%" table-layout="fixed">
<tbody><tr class="left-column"><td class="outer-table-cell" valign="top"><table class="table" width="100%" vspace="15">
<thead><tr class="yui-dt-even yui-dt-first"><td colspan="2"><h3> Details</h3></td></tr></thead>
<tbody>
<tr>
<td class="Label" width="250">Born (Age)</td>
<td class="Value">
</td>
</tr>
<tr>
<td class="Label" width="250">Gender</td>
<td class="Value">
</td>
</tr>
<tr>
<td class="Label" width="250">Country of Birth</td>
<td class="Value">-</td>
</tr>
<tr>
<td class="Label" width="250">Marital Status</td>
<td class="Value">-</td>
</tr>
<tr>
<td class="Label" width="250">Occupation</td>
<td class="Value">-</td>
</tr>
<tr>
<td class="Label" width="250">Ethnicity</td>
<td class="Value">-</td>
</tr>
<tr>
<td class="Label" width="250">Ethnicity</td>
<td class="Value">-</td>
</tr>
<tr>
<td class="Label" width="250">Ethnicity</td>
<td class="Value">-</td>
</tr>
<tr><td class="Label" width="250">Religion</td>
<td class="Value">-</td>
</tr><tr>
<td class="Label" width="250">Primary Language</td>
<td class="Value">-</td>
</tr>
<tr>
<td class="Label" width="250">Aliases</td>
<td class="Value">-</td>
</tr>
</tbody>
</table></td></tr>
</tbody>
</table></td></tr>
</tbody></table>
</div>
How do I get the value of second row My xpath works when I checked in the dev tools under console space . but when i copied to my code selenium I get an error the xpath can't find the element
My Xpath :
$x(".//div[@id='less_detail']/table/tbody/tr/td[1]/table[1]/tbody[1]/tr[1]/td[1]/table/tbody/tr[2]/td[1]")
My c# code :
for(int i=1; i <= NumberofFields; i++)
{
lblpatientdetails.Add(driver.FindElement(By.XPath(".//div[@id='less_detail']/table/tbody/tr/td[1]/table[1]/tbody[1]/tr[1]/td[1]/table/tbody/tr[" + i + "]/td[1]")).Text);
if (driver.FindElements(By.XPath(".//div[@id='less_detail']/table/tbody/tr/td[1]/table[1]/tbody[1]/tr[1]/td[1]/table/tbody/tr/td[@class='Value']")).Count > 0)
{
lblpatinetdetailsvalues.Add(driver.FindElement(By.XPath(".//div[@id='less_detail']/table/tbody/tr/td[1]/table[1]/tbody[1]/tr[1]/td[1]/table/tbody[1]/tr[" + i + "]/td[@class='Value']")).Text);
}
else
{
lblpatinetdetailsvalues.Add(ClinicalPortalConstants.NOT_AVAILABLE);