셀레늄 2의 테이블에서 값을 얻는 더 좋은 방법이 있는지 궁금합니다. 현재 각 TR에 대해 2 개의 루프를 사용하고 있으며 모든 TR에 대해 각 TR 루프 내에서 루프를 사용하고 있습니다. 그래서 예를 들어 10 열이있는 테이블 행이 있으면 10 번 반복하고 텍스트 값을 꺼냅니다. 그것은 나에게 clunky 보인다.셀레늄 2 및 HTML 테이블
내 테이블 행은 너무
<tr id="cTestData" class="odd">
<td class="date_activated">08/31/2011</td>
<td class="date_redeemed"> Not redeemed * </td>
<td class="expiration_date">09/01/2011</td>
<td class="product"> State of Maine </td>
<td class="value">$1.00</td>
<td class="store"> – – – </td>
<td class="offer_details">
</tr>
처럼 내가 나에게 date_activated 클래스 =와 TD 요소를 얻을 각 테이블 행에 대해 말할 수 있어야한다고 생각하고 날짜를 반환했습니다 보인다. 나는 몇 가지를 시도했지만 내 실제 코드는
for(WebElement trElement : tr_collection)
{
List<WebElement> td_collection=trElement.findElements(By.xpath("td"));
System.out.println("NUMBER OF COLUMNS="+td_collection.size());
col_num=1;
HashMap actInfo = new HashMap(); // new hashmap for each line inthe result set
if(!td_collection.isEmpty() && td_collection.size() != 1){
for(WebElement tdElement : td_collection)
{
System.out.println("Node Name=== " + tdElement.getAttribute("class"));
System.out.println("Node Value=== " + tdElement.getText());
actInfo.put(tdElement.getAttribute("class"), tdElement.getText());
col_num++;
}
masterMap.add(actInfo);
} // end if
row_num++;
}
나는 일반적으로 xpaths를 피하려고 노력하지만, 더 좋은 해결책을 찾을 때까지 잘 작동합니다. 고맙습니다 – ducati1212