0

ich eine seltsame Tabelle, die ich in einer Schleife wollen über die DatenHtmlagilitypack Loop Through Table - Verschachtelte innerhalb

Tabelle html zu kratzen ist:

<table class="footable footable-loaded default breakpoint"> 
<thead> 
    <tr> 
     <th data-class="expand" data-type="numeric" class="footable-sortable"> 
      Container 

      <span class="footable-sort-indicator"></span> 
     </th> 
     <th data-sort-initial="true" class="footable-sortable"> 
      Cnt Type 

      <span class="footable-sort-indicator"></span> 
     </th> 
     <th data-hide="all" class="footable-sortable" style="display: none;"> 
      <span class="footable-sort-indicator"></span> 
     </th> 
    </tr> 
</thead> 
<tbody id="ContentPlaceHolder1_con_mov"> 
    <tr class="koyu footable-detail-show"> 
     <td data-value="0" class="expand">CAIU2181527</td> 
     <td>20'DC</td> 
     <td style="display: none;"> 
      <div style="display:inline-block;width:100%" id="mHeader"> 
       <div style="float:left;width:33%" class="mov_div">LOCATION</div> 
       <div style="float:left;width:33%" class="mov_div">DATE</div> 
       <div style="float:left;width:33%" class="mov_div">MOVEMENT</div> 
      </div> 
      <div style="display:inline-block;width:100%"> 
       <div style="float:left;width:33%" class="mov_div">KAAN KALKAVAN, IE1729W</div> 
       <div style="float:left;width:33%" class="mov_div">07.20.2017</div> 
       <div style="float:left;width:33%" class="mov_div">LOADED TO VESSEL </div> 
       <div> 
        <div style="display:inline-block;width:100%"> 
         <div style="float:left;width:33%" class="mov_div">TR, IZMIR</div> 
         <div style="float:left;width:33%" class="mov_div">07.17.2017</div> 
         <div style="float:left;width:33%" class="mov_div">GATE IN FULL </div> 
         <div> 
          <div style="display:inline-block;width:100%"> 
           <div style="float:left;width:33%" class="mov_div">TR, IZMIR</div> 
           <div style="float:left;width:33%" class="mov_div">07.17.2017</div> 
           <div style="float:left;width:33%" class="mov_div">DISPATCHED EMPTY TO SHIPPER </div> 
           <div> 
            <div style="display:inline-block;width:100%"> 
             <div style="float:left;width:33%" class="mov_div">TR, IZMIR</div> 
             <div style="float:left;width:33%" class="mov_div">07.17.2017</div> 
             <div style="float:left;width:33%" class="mov_div">BOOKED </div> 
             <div></div> 
            </div> 
           </div> 
          </div> 
         </div> 
        </div> 
       </div> 
      </div> 
     </td> 
    </tr> 
    <tr class="footable-row-detail"> 
     <td class="footable-cell-detail" colspan="2"> 
      <div class="footable-row-detail-inner"> 
       <div> 
        <strong></strong> 
        <div style="display:inline-block;width:100%" id="mHeader"> 
         <div style="float:left;width:33%" class="mov_div">LOCATION</div> 
         <div style="float:left;width:33%" class="mov_div">DATE</div> 
         <div style="float:left;width:33%" class="mov_div">MOVEMENT</div> 
        </div> 
        <div style="display:inline-block;width:100%"> 
         <div style="float:left;width:33%" class="mov_div">KAAN KALKAVAN, IE1729W</div> 
         <div style="float:left;width:33%" class="mov_div">07.20.2017</div> 
         <div style="float:left;width:33%" class="mov_div">LOADED TO VESSEL </div> 
         <div> 
          <div style="display:inline-block;width:100%"> 
           <div style="float:left;width:33%" class="mov_div">TR, IZMIR</div> 
           <div style="float:left;width:33%" class="mov_div">07.17.2017</div> 
           <div style="float:left;width:33%" class="mov_div">GATE IN FULL </div> 
           <div> 
            <div style="display:inline-block;width:100%"> 
             <div style="float:left;width:33%" class="mov_div">TR, IZMIR</div> 
             <div style="float:left;width:33%" class="mov_div">07.17.2017</div> 
             <div style="float:left;width:33%" class="mov_div">DISPATCHED EMPTY TO SHIPPER </div> 
             <div> 
              <div style="display:inline-block;width:100%"> 
               <div style="float:left;width:33%" class="mov_div">TR, IZMIR</div> 
               <div style="float:left;width:33%" class="mov_div">07.17.2017</div> 
               <div style="float:left;width:33%" class="mov_div">BOOKED </div> 
               <div></div> 
              </div> 
             </div> 
            </div> 
           </div> 
          </div> 
         </div> 
        </div> 
       </div> 
      </div> 
     </td> 
    </tr> 
</tbody> 
<tfoot id="ContentPlaceHolder1_con_footer"></tfoot> 

ich normalerweise Schleife durch regelmäßige Tabellen mit:

IWebElement element1 = driver.FindElement(By.XPath("something")); 
       String contents = (String)((IJavaScriptExecutor)driver).ExecuteScript("return arguments[0].outerHTML;", element1); 
       var node = HtmlNode.CreateNode(contents); 
       foreach (var eachNode in node.SelectNodes("//something/tr")) 
       { 
        var cells = eachNode.SelectNodes(".//td"); 
        cd = new TableDetail(); 

        for (int i = 0; i < cells.Count(); i++) 
        { 
        Getting data from table 
        } 
       } 

Irgendwelche Ideen, wie ich oben Tabelle durchschleifen kann? Da es auf traditionelle Weise verschachtelt ist, wird es nicht funktionieren.

Antwort

0

Ich schaffe es, indem Sie HAP Css Selector verwenden;

IWebElement element1 = driver.FindElement(By.XPath("//*[@id=\"ContentPlaceHolder1_con_mov\"]/tr[1]")); 
       String contents = (String)((IJavaScriptExecutor)driver).ExecuteScript("return arguments[0].outerHTML;", element1); 
       var node = HtmlNode.CreateNode(contents); 
       foreach (var eachNode in node.QuerySelectorAll("div[style=display:inline-block;width:100%]")) 
       { 
        var cells = eachNode.SelectNodes("div[@class=\"mov_div\"]");