2016-07-31 2 views
0

내가 셀레늄 새로운 오전과 내가 내가 알고 싶어셀레늄에서 테이블을 반복하는 방법?

<table> 
 
    <tr> 
 
    <td style="width:5px"> 
 
    </td> 
 
    <td> 
 
     <table class="reportTable" id="Allocations"> 
 
     <tbody> 
 
      <tr class="table_header"> 
 
      <td style="width:5px;"> 
 
       <img class="HideImage" src="Images/minus.gif" alt="Hide Details"> 
 
      </td> 
 
      <td style="width:33%"> 
 
       Channel of Trade</td> 
 
      <td style="width:33%"> 
 
       PILOT TRAVEL CENTE-122194-W/S - UNB Contract</td> 
 
      <td style="width:33%"> 
 
       <span id="TruckLoading_10142602_Info" style="COLOR: white;text-decoration:underline;cursor:pointer"> 
 
Trucks loading - 0</span> 
 
      </td> 
 
      </tr> 
 
      <tr> 
 
      <td style="width:5px;"> 
 
      </td> 
 
      <td colspan="3"> 
 
       <table rules="rows" class="reportTable" font-family="Tahoma" pagerstyle-visible="False" id="TerminalGrid" border="1"> 
 
       <tbody> 
 
        <tr class="productlabel2" align="left"> 
 
        <td scope="col" style="width:5px;"> 
 
        </td> 
 
        <td> 
 
         Product Details</td> 
 
        </tr> 
 
        <tr class="hdr2"> 
 
        <td scope="col" style="width:5px;"> 
 
        </td> 
 
        <td scope="col"> 
 
         Fuel Type</td> 
 
        </tr> 
 
        <tr class="FuelTypeHeader"> 
 
        <td style="width:5px;border:none" onclick="ShowHideDetails(this)"> 
 
         <img class="HideImage" src="Images/minus.gif" alt="Hide Details" id="Fuel_Img"> 
 
        </td> 
 
        <td style="border-left:none;border-right:none; padding-left:3px"> 
 
         <table id="C_V" style="width:100%;border-collapse:collapse; border:none; padding:0px 0px 0px 0px; margin:0px 0px 0px 0px;"> 
 
         <tbody> 
 
          <tr> 
 
          <td style="width:20em;"> 
 
           <span> 
 
DSL - LSD/ULSD</span> 
 
          </td> 
 
          <td style="width:60em;"> 
 
           <span id="CVSpan"> 
 
<span style="margin-right:10px"> 
 
<span style="float:left;padding-top:3px"> 
 
Currently:</span> 
 
           <span style="float:left;width:6em;padding-top:2px; margin-left:5px; margin-right:5px;margin-top:2px;padding-bottom:2px; text-align:center; background-color:#00FF00;"> 
 
Available</span> 
 
           <span style="float:left; padding-top:3px"> 
 
<b> 
 
30,839</b> 
 
gallons remaining until Mon 8/1/2016 12:00:00 AM CDT</span> 
 
           </span> 
 
           </span> 
 
          </td> 
 
          <td align="right"> 
 
          </td> 
 
          </tr> 
 
         </tbody> 
 
         </table> 
 
        </td> 
 
        </tr> 
 
        <tr style=""> 
 
        <td style="width:5px;"> 
 
        </td> 
 
        <td> 
 
         <table id="ProdDetails" rules="all" pagerstyle-visible="False" style="width: 100%" border="1"> 
 
         <tbody> 
 
          <tr class="table_header2"> 
 
          <th scope="col"> 
 
           Nominated Volume</th> 
 
          <th scope="col"> 
 
           Allocation Period</th> 
 
          <th scope="col"> 
 
           Allocation %</th> 
 
          <th scope="col"> 
 
           Allocation Start Amt</th> 
 
          <th scope="col"> 
 
           Allocation Lifted</th> 
 
          <th scope="col"> 
 
           Allocation Remaining</th> 
 
          <th scope="col"> 
 
           GPO Allowance</th> 
 
          <th scope="col" class="center width8em"> 
 
           GPO Remaining</th> 
 
          <th scope="col"> 
 
           Category Status</th> 
 
          <th scope="col"> 
 
           Ratability Status</th> 
 
          <th scope="col"> 
 
           Next Scheduled Refresh Date</th> 
 
          <th scope="col"> 
 
           Reference ID</th> 
 
          </tr> 
 
          <tr class="tablerow2"> 
 
          <td class="right width8em"> 
 
           41,118</td> 
 
          <td class="center width10em"> 
 
           Daily</td> 
 
          <td class="right"> 
 
           75%</td> 
 
          <td class="right"> 
 
           30,839</td> 
 
          <td class="right"> 
 
           0</td> 
 
          <td class="right"> 
 
           30,839</td> 
 
          <td class="right"> 
 
           0</td> 
 
          <td class="right width8em bold" id="GPO_Rmd"> 
 

 
           0 
 
          </td> 
 
          <td class="center" style="background-color:#00FF00;"> 
 
           Available</td> 
 
          <td class="center" style="background-color:#0099CC;"> 
 
           Below Trend</td> 
 
          <td class="center width20em"> 
 
           8/1/2016 12:00:00 AM CDT</td> 
 
          <td class="center width20emWordWrap"> 
 
           DSL - LSD/ULSD</td> 
 
          </tr> 
 
          <tr class="tablerow2"> 
 
          <td class="right width8em"> 
 
           287,826</td> 
 
          <td class="center width10em"> 
 
           Weekly</td> 
 
          <td class="right"> 
 
           125%</td> 
 
          <td class="right"> 
 
           359,783</td> 
 
          <td class="right"> 
 
           114,083</td> 
 
          <td class="right"> 
 
           245,700</td> 
 
          <td class="right"> 
 
           0</td> 
 
          <td class="right width8em bold" id="GPO_Rmd"> 
 

 
           0 
 
          </td> 
 
          <td class="center" style="background-color:#00FF00;"> 
 
           Available</td> 
 
          <td class="center" style="background-color:#0099CC;"> 
 
           Below Trend</td> 
 
          <td class="center width20em"> 
 
           8/4/2016 12:00:00 AM CDT</td> 
 
          <td class="center width20emWordWrap"> 
 
           DSL - LSD/ULSD</td> 
 
          </tr> 
 
          <tr class="tablerow2"> 
 
          <td class="right width8em"> 
 
           1,233,540</td> 
 
          <td class="center width10em"> 
 
           Monthly</td> 
 
          <td class="right"> 
 
           115%</td> 
 
          <td class="right"> 
 
           1,418,571</td> 
 
          <td class="right"> 
 
           1,361,264</td> 
 
          <td class="right"> 
 
           57,307</td> 
 
          <td class="right"> 
 
           0</td> 
 
          <td class="right width8em bold" id="GPO_Rmd"> 
 

 
           0 
 
          </td> 
 
          <td class="center" style="background-color:#FFFF00;"> 
 
           Low</td> 
 
          <td class="center" style="background-color:#00CC00;"> 
 
           On Track</td> 
 
          <td class="center width20em"> 
 
           8/1/2016 12:00:00 AM CDT</td> 
 
          <td class="center width20emWordWrap"> 
 
           DSL - LSD/ULSD</td> 
 
          </tr> 
 
         </tbody> 
 
         </table> 
 
        </td> 
 
        </tr> 
 
        <tr id="GPO_Row"> 
 
        <td style="width:5px;"> 
 
        </td> 
 
        <td> 
 
        </td> 
 
        </tr> 
 
       </tbody> 
 
       </table> 
 
      </td> 
 
      </tr> 
 
      <tr class="table_header"> 
 
      <td style="width:5px;" onclick="ShowHideDetails(this)"> 
 
       <img class="HideImage" src="Images/minus.gif" alt="Hide Details"> 
 
      </td> 
 
      <td style="width:33%"> 
 
       Channel of Trade</td> 
 
      <td style="width:33%"> 
 
       PILOT TRAVEL CENTE-122194-W/S - UNB Fwrd Cont</td> 
 
      <td style="width:33%"> 
 
       <span id="TruckLoading_17049566_Info" style="COLOR: white;text-decoration:underline;cursor:pointer" onclick="GetTruckLoadingInformationJS(this,17049566);"> 
 
Trucks loading - 0</span> 
 
      </td> 
 
      </tr> 
 
      <tr> 
 
      <td style="width:5px;"> 
 
      </td> 
 
      <td colspan="3"> 
 
       <table rules="rows" class="reportTable" font-family="Tahoma" pagerstyle-visible="False" id="TerminalGrid" border="1"> 
 
       <tbody> 
 
        <tr class="productlabel2" align="left"> 
 
        <td scope="col" style="width:5px;"> 
 
        </td> 
 
        <td> 
 
         Product Details</td> 
 
        </tr> 
 
        <tr class="hdr2"> 
 
        <td scope="col" style="width:5px;"> 
 
        </td> 
 
        <td scope="col"> 
 
         Fuel Type</td> 
 
        </tr> 
 
        <tr class="FuelTypeHeader"> 
 
        <td style="width:5px;border:none" onclick="ShowHideDetails(this)"> 
 
         <img class="HideImage" src="Images/minus.gif" alt="Hide Details" id="Fuel_Img"> 
 
        </td> 
 
        <td style="border-left:none;border-right:none; padding-left:3px"> 
 
         <table id="C_V" style="width:100%;border-collapse:collapse; border:none; padding:0px 0px 0px 0px; margin:0px 0px 0px 0px;"> 
 
         <tbody> 
 
          <tr> 
 
          <td style="width:20em;"> 
 
           <span> 
 
DSL - LSD/ULSD</span> 
 
          </td> 
 
          <td style="width:60em;"> 
 
           <span id="CVSpan"> 
 
<span style="margin-right:10px"> 
 
<span style="float:left;padding-top:3px"> 
 
Currently:</span> 
 
           <span style="float:left;width:6em;padding-top:2px; margin-left:5px; margin-right:5px;margin-top:2px;padding-bottom:2px; text-align:center; background-color:#FF0000;"> 
 
Out</span> 
 
           <span style="float:left; padding-top:3px"> 
 
<b> 
 
0</b> 
 
gallons remaining until Mon 8/1/2016 12:00:00 AM CDT</span> 
 
           </span> 
 
           </span> 
 
          </td> 
 
          <td align="right"> 
 
          </td> 
 
          </tr> 
 
         </tbody> 
 
         </table> 
 
        </td> 
 
        </tr> 
 
        <tr style=""> 
 
        <td style="width:5px;"> 
 
        </td> 
 
        <td> 
 
         <table id="ProdDetails" rules="all" pagerstyle-visible="False" style="width: 100%" border="1"> 
 
         <tbody> 
 
          <tr class="table_header2"> 
 
          <th scope="col"> 
 
           Nominated Volume</th> 
 
          <th scope="col"> 
 
           Allocation Period</th> 
 
          <th scope="col"> 
 
           Allocation %</th> 
 
          <th scope="col"> 
 
           Allocation Start Amt</th> 
 
          <th scope="col"> 
 
           Allocation Lifted</th> 
 
          <th scope="col"> 
 
           Allocation Remaining</th> 
 
          <th scope="col"> 
 
           GPO Allowance</th> 
 
          <th scope="col" class="center width8em"> 
 
           GPO Remaining</th> 
 
          <th scope="col"> 
 
           Category Status</th> 
 
          <th scope="col"> 
 
           Ratability Status</th> 
 
          <th scope="col"> 
 
           Next Scheduled Refresh Date</th> 
 
          <th scope="col"> 
 
           Reference ID</th> 
 
          </tr> 
 
          <tr class="tablerow2"> 
 
          <td class="right width8em"> 
 
           0</td> 
 
          <td class="center width10em"> 
 
           Custom 1 day(s)</td> 
 
          <td class="right"> 
 
           100%</td> 
 
          <td class="right"> 
 
           0</td> 
 
          <td class="right"> 
 
           0</td> 
 
          <td class="right"> 
 
           0</td> 
 
          <td class="right"> 
 
           0</td> 
 
          <td class="right width8em bold" id="GPO_Rmd"> 
 

 
           0 
 
          </td> 
 
          <td class="center" style="background-color:#FF0000;"> 
 
           Out</td> 
 
          <td class="center" style="background-color:#0099CC;"> 
 
           Below Trend</td> 
 
          <td class="center width20em"> 
 
           8/1/2016 12:00:00 AM CDT</td> 
 
          <td class="center width20emWordWrap"> 
 
           MERC-DSL</td> 
 
          </tr> 
 
         </tbody> 
 
         </table> 
 
        </td> 
 
        </tr> 
 
        <tr id="GPO_Row"> 
 
        <td style="width:5px;"> 
 
        </td> 
 
        <td> 
 
        </td> 
 
        </tr> 
 
       </tbody> 
 
       </table> 
 
      </td> 
 
      </tr> 
 
     </tbody> 
 
     </table> 
 
    </td> 
 
    </tr> 
 
</table>

해당 테이블의 값을 테이블을 통해 루프 필요 얻을이 질문을 얼마나 그래서 루프 테이블에 나는 테이블의 데이터와 함께 "PILOT TRAVEL CENTE-122194-W/S-UNB 계약", "PILOT TRAVEL CENTE-122194-W/S-UNB Fwrd Cont"및 "UNB Spot"계약을 체결 할 수 있습니다 . 미리 감사드립니다.

+0

당신은 무엇을 당신 자신을 시험해 보셨습니까 ?? 그리고 결과는 무엇입니까 ?? –

+0

나는 테이블을 반복하려했지만 처음 3 개의 레코드와 계약을 맺고 있었고 계약도 4 번째 행에 추가되었다. 나는 첫 번째 3 행 oly의 계약과 4 행의 첫 계약을 얻고 싶었습니다 –

+0

어떤 것을 이미 시도했는지 공유 할 수 있습니까? –

답변

1

좋아 방금 논리가 동일 구문을 변경 다른 언어를 사용하는 경우 내가 C#을

//Init table element (in this case by tag name but better chose by id or Name) 
IWebElement tableElement = driver.FindElement(By.TagName("table")); 

//Init TR elements from table we found into list 
IList<IWebElement> trCollection = tableElement.FindElements(By.TagName("tr")); 
//define TD elements collection. 
IList<IWebElement> tdCollection; 

//loop every row in the table and init the columns to list 
foreach(IWebElement element in trCollection) 
{ 
    tdCollection = element.FindElements(By.TagName("td")); 

    //now in the List you have all the columns of the row 
    string column1 = tdCollection[0].Text; 
    string column2 = tdCollection[1].Text; 
    ... 
} 

당신에게 예를 줄 것이다 당신이 그렇게 사용하는 언어에 대해 아무 말도하지 않았다.

+0

동일한 로직을 사용하고 있지만'element' = null이되어 –

+0

테이블에 tr 태그가 없으므로 .. –

+0

tr 카운트가 완벽 해졌습니다. 즉 문제는 단지 요소에 불과합니다. foreach에 –

관련 문제