我想循环遍历表,直到Td文本为" Dispatched Export To Shipper"。我不希望它检查下面的节点。只有前8行。但条件应该是td文本。有什么想法吗?
表样本:
<table role="grid" data-role="selectable" class="k-selectable">
<colgroup>
<col style="width:115px">
<col>
<col>
<col>
<col>
<col style="width:70px">
<col style="width:50px">
<col>
</colgroup>
<thead class="k-grid-header" role="rowgroup">
<tr role="row">
<th class="k-header" data-field="XNS_DTTM" data-index="0" data-title="Date" scope="col">
<span class="k-link">Date</span>
</th>
<th class="k-header" data-field="ATLOC_NAME" data-index="1" data-title="Location" scope="col">
<span class="k-link">Location</span>
</th>
<th class="k-header" data-field="TOLOC_NAME" data-index="2" data-title="To Location" scope="col">
<span class="k-link">To Location</span>
</th>
<th class="k-header" data-field="BL_OR_BKG_NO" data-index="3" data-title="BL/BKG" scope="col">
<span class="k-link">BL/BKG</span>
</th>
<th class="k-header" data-field="VSL_NAME" data-index="4" data-title="Vessel" scope="col">
<span class="k-link">Vessel</span>
</th>
<th class="k-header" data-field="VOY_CODE" data-index="5" data-title="Voy" scope="col">
<span class="k-link">Voy</span>
</th>
<th class="k-header" data-field="LINE_CODE" data-index="6" data-title="Line" scope="col">
<span class="k-link">Line</span>
</th>
<th class="k-header" data-field="XNS_DSCR" data-index="7" data-title="Description" scope="col">
<span class="k-link">Description</span>
</th>
</tr>
</thead>
<tbody role="rowgroup">
<tr data-uid="affa9830-8556-4dcd-bcbc-4f54f0a56cc6" role="row">
<td style="vertical-align:top;" role="gridcell">28-JUN-2017 09:30</td>
<td style="vertical-align:top;" role="gridcell">COLOMBO - SOUTH ASIA GATEWAY TERMINAL</td>
<td style="vertical-align:top;" role="gridcell"></td>
<td style="vertical-align:top;" role="gridcell">
<span title="Login into MOLPOWER to see the Container details.">--</span>
</td>
<td style="vertical-align:top;" role="gridcell">BELLAVIA/BLV</td>
<td style="vertical-align:top;" role="gridcell">0034E</td>
<td style="vertical-align:top;" role="gridcell">HSX</td>
<td style="vertical-align:top;" role="gridcell">Landed Transshipment</td>
</tr>
<tr class="k-alt" data-uid="634db05f-8f85-49e4-b143-13971126591f" role="row">
<td style="vertical-align:top;" role="gridcell">28-JUN-2017 08:42</td>
<td style="vertical-align:top;" role="gridcell">COLOMBO - SOUTH ASIA GATEWAY TERMINAL</td>
<td style="vertical-align:top;" role="gridcell"></td>
<td style="vertical-align:top;" role="gridcell">
<span title="Login into MOLPOWER to see the Container details.">--</span>
</td>
<td style="vertical-align:top;" role="gridcell">BELLAVIA/BLV</td>
<td style="vertical-align:top;" role="gridcell">0034E</td>
<td style="vertical-align:top;" role="gridcell">HSX</td>
<td style="vertical-align:top;" role="gridcell">Vessel arrived at port</td>
</tr>
<tr data-uid="bdac4da1-ef1e-49f8-bb85-ff8bda21ff65" role="row">
<td style="vertical-align:top;" role="gridcell">25-JUN-2017 18:18</td>
<td style="vertical-align:top;" role="gridcell">PIPAVAV-APM TERMINALS</td>
<td style="vertical-align:top;" role="gridcell">COLOMBO - SOUTH ASIA GATEWAY TERMINAL</td>
<td style="vertical-align:top;" role="gridcell">
<span title="Login into MOLPOWER to see the Container details.">--</span>
</td>
<td style="vertical-align:top;" role="gridcell">BELLAVIA/BLV</td>
<td style="vertical-align:top;" role="gridcell">0034E</td>
<td style="vertical-align:top;" role="gridcell">HSX</td>
<td style="vertical-align:top;" role="gridcell">Vessel depart from the port</td>
</tr>
<tr class="k-alt" data-uid="403e9c6a-aec8-4124-b74b-749a98b52675" role="row">
<td style="vertical-align:top;" role="gridcell">25-JUN-2017 13:57</td>
<td style="vertical-align:top;" role="gridcell">PIPAVAV-APM TERMINALS</td>
<td style="vertical-align:top;" role="gridcell">COLOMBO - SOUTH ASIA GATEWAY TERMINAL</td>
<td style="vertical-align:top;" role="gridcell">
<span title="Login into MOLPOWER to see the Container details.">--</span>
</td>
<td style="vertical-align:top;" role="gridcell">BELLAVIA/BLV</td>
<td style="vertical-align:top;" role="gridcell">0034E</td>
<td style="vertical-align:top;" role="gridcell">HSX</td>
<td style="vertical-align:top;" role="gridcell">Loaded on Vessel</td>
</tr>
<tr data-uid="8e7c6913-a4a4-4ef9-a6a1-d16b9a3b7d30" role="row">
<td style="vertical-align:top;" role="gridcell">20-JUN-2017 20:27</td>
<td style="vertical-align:top;" role="gridcell">PIPAVAV-APM TERMINALS</td>
<td style="vertical-align:top;" role="gridcell"></td>
<td style="vertical-align:top;" role="gridcell">
<span title="Login into MOLPOWER to see the Container details.">--</span>
</td>
<td style="vertical-align:top;" role="gridcell">BELLAVIA/BLV</td>
<td style="vertical-align:top;" role="gridcell">0034E</td>
<td style="vertical-align:top;" role="gridcell">HSX</td>
<td style="vertical-align:top;" role="gridcell">In-Gate Export At Final Facility at LP</td>
</tr>
<tr class="k-alt" data-uid="e5b3a2a2-4ead-4480-a088-5d0bc5c2bfa6" role="row">
<td style="vertical-align:top;" role="gridcell">20-JUN-2017 07:15</td>
<td style="vertical-align:top;" role="gridcell">AHMEDABAD - ICD AHMEDABAD/ ICD KHODIYAR</td>
<td style="vertical-align:top;" role="gridcell">PIPAVAV-APM TERMINALS</td>
<td style="vertical-align:top;" role="gridcell">
<span title="Login into MOLPOWER to see the Container details.">--</span>
</td>
<td style="vertical-align:top;" role="gridcell">BELLAVIA/BLV</td>
<td style="vertical-align:top;" role="gridcell">0034E</td>
<td style="vertical-align:top;" role="gridcell">HSX</td>
<td style="vertical-align:top;" role="gridcell">Transit Export</td>
</tr>
<tr data-uid="c4d7f433-3cb2-4a2f-b0e8-19eae9545cd3" role="row">
<td style="vertical-align:top;" role="gridcell">16-JUN-2017 21:16</td>
<td style="vertical-align:top;" role="gridcell">AHMEDABAD - ICD AHMEDABAD/ ICD KHODIYAR</td>
<td style="vertical-align:top;" role="gridcell"></td>
<td style="vertical-align:top;" role="gridcell">
<span title="Login into MOLPOWER to see the Container details.">--</span>
</td>
<td style="vertical-align:top;" role="gridcell">BELLAVIA/BLV</td>
<td style="vertical-align:top;" role="gridcell">0034E</td>
<td style="vertical-align:top;" role="gridcell">HSX</td>
<td style="vertical-align:top;" role="gridcell">Received Export</td>
</tr>
<tr class="k-alt" data-uid="a8593a5d-4bd6-4714-80c8-04e55a3140a9" role="row">
<td style="vertical-align:top;" role="gridcell">15-JUN-2017 17:00</td>
<td style="vertical-align:top;" role="gridcell">AHMADABAD - QUEST CONTAINER DEPO</td>
<td style="vertical-align:top;" role="gridcell">AHMADABAD - QUEST CONTAINER DEPO</td>
<td style="vertical-align:top;" role="gridcell">
<span title="Login into MOLPOWER to see the Container details.">--</span>
</td>
<td style="vertical-align:top;" role="gridcell">BELLAVIA/BLV</td>
<td style="vertical-align:top;" role="gridcell">0034E</td>
<td style="vertical-align:top;" role="gridcell">HSX</td>
<td style="vertical-align:top;" role="gridcell">Dispatched Export To Shipper</td>
</tr>
<tr data-uid="cbdc7f97-5e8d-48c9-900b-8031ee6a6fe5" role="row">
<td style="vertical-align:top;" role="gridcell">03-JUN-2017 11:00</td>
<td style="vertical-align:top;" role="gridcell">AHMADABAD - QUEST CONTAINER DEPO</td>
<td style="vertical-align:top;" role="gridcell"></td>
<td style="vertical-align:top;" role="gridcell">
<span title="Login into MOLPOWER to see the Container details.">--</span>
</td>
<td style="vertical-align:top;" role="gridcell"></td>
<td style="vertical-align:top;" role="gridcell"></td>
<td style="vertical-align:top;" role="gridcell"></td>
<td style="vertical-align:top;" role="gridcell">In Empty And Available</td>
</tr>
<tr class="k-alt" data-uid="6c033a15-a900-47aa-8f26-642e012a97b0" role="row">
<td style="vertical-align:top;" role="gridcell">03-JUN-2017 01:38</td>
<td style="vertical-align:top;" role="gridcell">AHMEDABAD - ICD AHMEDABAD/ ICD KHODIYAR</td>
<td style="vertical-align:top;" role="gridcell">AHMEDABAD - ICD AHMEDABAD/ ICD KHODIYAR</td>
<td style="vertical-align:top;" role="gridcell">
<span title="Login into MOLPOWER to see the Container details.">--</span>
</td>
<td style="vertical-align:top;" role="gridcell">WAN HAI 501/W501</td>
<td style="vertical-align:top;" role="gridcell">0117W</td>
<td style="vertical-align:top;" role="gridcell">HSX</td>
<td style="vertical-align:top;" role="gridcell">Out-Gate Import To Consignee</td>
</tr>
</tbody>
控制器示例:
foreach (var eachNode in driver.FindElements(By.XPath("//*[@id=\"gridEqpHistory\"]/table/tbody/tr")))
{
var cells = eachNode.FindElements(By.TagName("td"));
cd = new ContainerDetail();
for (int i = 0; i < cells.Count(); i++)
{
cd.ContainerNo = containerNo;
cd.Location = cells[1].Text.Trim();
cd.ActionType = cells[7].Text.Trim();
string s = cells[0].Text;
DateTime dt = Convert.ToDateTime(s);
if (_minDate > dt) _minDate = dt;
cd.ActionDate = dt;
cd.Vessel = cells[4].Text.Split('/').First().Trim();
cd.Voyage = cells[5].Text.Trim();
}
答案 0 :(得分:0)
如果您只想获得包含所需数据的前8个tr
元素,可以尝试在XPath
表达式下面使用
//tr[not(preceding-sibling::tr[td="Dispatched Export To Shipper"]) and not(th)]