Reputation: 5010
I need to select a value of a td based on another td's text in the same row. The XPath should be the same and only text will be changeable. In the following HTML, I have to select $33.00
based on Labor
, $0.66
based on Finance
, $33.66
based on Total
, and so on.
* {margin: 0; padding: 0;}
body {font-family:"Times New Roman", "serif","Arial","tahoma"; font-size: 12px;}
.center {width: 1200px; margin: auto;}
.top-left {float: left; width: 70%; font-weight: bold;}
.top-right {float: right; width: 30%; text-align: right;}
h2 {margin: 0 0 10px; border-bottom: 1px solid #ccc; padding: 10px 0;}
.terms {margin: 15px 0 0; font-weight: normal;}
.invoice-to {margin: 15px 0 0;}
.clear {clear: both;}
.table-holder {margin: 50px 0 0; font-size: 12px;}
table {border-collapse: collapse;}
.table-holder table th {border: 1px solid #ccc; border-bottom: 2px solid #ccc; text-align: left; padding: 4px 2px;}
.table-holder table td {border: 1px solid #ccc; padding: 4px 2px;}
.table-holder table td p {padding: 4px 2px;}
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<title>Invoice :: 6</title>
</head>
<body style="">
<div class="center" id="wrapper">
<h2>INVOICE</h2>
<div class="table-holder">
<table width="100%" border="0" cellspacing="0" cellpadding="0" id="tbl" style="font-size: 9px;">
<tbody><tr>
<th>Invoice ID</th>
<th>Fund</th>
<th>Work ID</th>
<th>Provider ID</th>
<th>Provider Name</th>
<th>Provider Location</th>
<th>Client</th>
<th>Project</th>
<th>Manager</th>
<th>Service Title</th>
<th>Location Name</th>
<th>Street</th>
<th>City</th>
<th>State</th>
<th>ZIP</th>
<th>Service Date</th>
<th>Completed Date</th>
<th>Approved Date</th>
<th>Total Hours</th>
<th>WO Subtotal</th>
<th>OAI Fee</th>
<th>Service Fee</th>
<th>International Fee</th>
<th>General Liability Liaison Fee</th>
<th>High Value Supply Fee</th>
<th>State Taxes Fee</th>
<th>Total Payment</th>
</tr>
<tr>
<td>6</td>
<td>ID# 20</td>
<td>WO177</td>
<td>695</td>
<td>Constantin Jenkins</td>
<td>CHAMPLIN, MN</td>
<td></td>
<td></td>
<td>Gideon Keebler</td>
<td>Basic Work Order</td>
<td></td>
<td>938 Randolph Avenue </td>
<td>Saint Paul</td>
<td>MN</td>
<td>55102</td>
<td>09/09/2020 8:00AM</td>
<td>09/09/2020 10:56PM</td>
<td>09/09/2020 10:56PM</td>
<td>0.00</td>
<td>$30.00</td>
<td>$0.00</td>
<td>$1.50</td>
<td>$0.00</td>
<td>$1.50</td>
<td>$0.00</td>
<td>$0.00</td>
<td>$33.00</td>
</tr>
<tr>
<td colspan="27" style="background: #ccc; padding: 1px;"></td>
</tr>
<tr>
<td colspan="25" style="border: none;"></td>
<td style="border: none;">
<p>Labor</p>
<p>Finance(2.00%)</p>
<p><strong>Total</strong></p>
</td>
<td style="border: none;" align="right">
<p>$33.00</p>
<p>$0.66</p>
<p><strong>$33.66</strong></p>
</td>
</tr>
</tbody></table>
</div>
</div>
</body>
</html>
Help me please someone
Upvotes: 1
Views: 567
Reputation: 5010
I've just modified @JaSON 's answer and now it's working fine
//td[contains(., "Finance")]/following-sibling::td/p[count(//p[contains(., "Finance")]/preceding-sibling::p) + 1]
Upvotes: 0
Reputation: 4869
Try this one to get required output:
//td[p="Total"]/following-sibling::td/p[count(//p[.="Total"]/preceding-sibling::p) + 1]
Upvotes: 1