2016-07-04 2 views
-2

이 경우 요소 수 (각 고객이 보유한 제품 수)를 계산해야합니다. 이것을 해결하려는 나의 시도는 "li"태그의 수를 세고 "ticket-type"에 액세스하는 것입니다. 방법이에 대한 어떤 제안을 달성 할 수있다?요소 수를 계산하십시오.

List<WebElement> labels = driver.findElements(By.xpath("//label[@class='ticket-type']")); 
int ProdNum = labels.size(); 
String strI1 = Integer.toString(ProdNum); 
System.out.print("Number of products on this card:" + strI1); 
// getting the name of the last product 
String LastProd = labels.get(labels.size() - 1).getText(); 
System.out.print("The last ordered product was:" + LastProd); 

이의이 .html 코드는 내가 계산해야 할 5 개 제품이있는 경우, 다음과 같습니다.

<div class="card-details row"> 
    <div class="pane base4"> 
    <div class="pane base4"> 
    <div class="vertical-accordion"> 
     <ul id="accordion-9" class="accordion"> 
      <li class="open-li"> 
      <a class="toggle-link open" href="#"> 
      <div class="accordion-drop" style="display: block;"> 
       <ul> 
        <li> 
         <label class="ticket-type">7 day megarider</label> 
         <label class="validity"> (7 day: 04 July to 10 July 2016) </label> 
        </li> 
        <li> 
        <li> 
        <li> 
        <li> 
       </ul> 
      </div> 
     </li> 
    </ul> 
    </div> 
</div> 
+0

은 (기준이 라인'driver.findElements의 문제 것입니다. xpath ("// label [@ class = 'ticket-type']"));'... –

+0

@Saurabh - 나는 라이트 카운트를 얻지 못하고있다. "li"태그와 같은 5 개의 제품이 있어야합니다. – AzMar

+0

당신은'driver.findElements (By.xpath ("// div [@ class = '아코디언 드롭']/ul/li"));' – Madhan

답변

0

아래의 코드를 시도하십시오 :

// Getting total count of all li tag elements 
List<WebElement> prodsCount = driver.findElements(By.xpath(".//div[@class='accordion-drop']/ul/li")); 
System.out.println("Total number of products are " + prodsCount.size()); 

// Getting the last item name 
String lastProdName = driver.findElement(By.xpath(".//div[@class='accordion-drop']/ul/li[last()]/lable[1]")).getText(); 
System.out.println("Last product name is " + lastProdName); 

희망이

+0

@Karthik - 여전히 첫 번째 줄에서 라이트 카운트를받지 못했습니다. – AzMar

+0

관찰하고있는 수치는 얼마입니까? –

+0

총 상품 수 : 20 개이지만 잘못 입력했지만 마지막 제품명이 정확합니다. 나는 xpath (".//div[@class='accordion-drop']/ul/li")가 여전히 수정 될 필요가 있다고 생각한다. – AzMar

0

이 시도 할 수 :

List<WebElement> numOfLiTag = driver.findElements(By.xpath(".//ul[@id='accordion-9']/li/div/ul/li[5]/label[1]")); 
    int liTagcount = numOfLiTag.size(); 
    String abc = driver.findElement(By.xpath(".//ul[@id='accordion-9']/li/div/ul/li[5]/label[1]")).getText(); 
관련 문제