2013-10-10 2 views
1

저는 Chrome 기반 채팅/메신저 플랫폼의 테스트 자동화 작업을하고 있습니다.Watir - Chrome - 모두 보이지 않는 "li"항목을 모두 검색하는 방법?

한 가지 경우는 모든 연락처 정보를 얻는 것입니다. 연락처는 그룹으로 배치되며 그룹 이름을 토글 클릭하여 표시하거나 숨길 수 있습니다.

나는 이미지를 게시하려고했지만, 난 충분히 명성 포인트 :(HTML 소스는 다음과 같다

이없는 말, 거절있어 :


<div id="connectionListItems"> 
     <ul class="connections" style="height: 2783px;"> 
     <li class="group collapsed" data-item-id="SUGAR" data-name="SUGAR" style="top: 0px;"> ... /li> 
     <li class="group collapsed" data-item-id="Desk Connections" data-name="Desk Connections" style="top: 23px;"> ... /li> 
     <li class="group expanded" data-item-id="Default" data-name="Default" style="top: 46px;"> 
      <span class="name"> Default <span class="count">(0/118)</span> </span> ... /li> 
     <li class="connection" data-item-id="Default~klxkqbs_tu-yahoo" style="top: 69px;"> 
      <span class="name">(ABN) James</span> </li> 
     <li class="connection" data-item-id="Default~klxkqbs_tq-yahoo" style="top: 92px;"> 
      <span class="name">(ABN) Justin</span> </li> 
     <li class="connection" data-item-id="Default~klxkqbs_wm-yahoo" style="top: 115px;"> 
      <span class="name">(ABN) Matt</span> </li> 
     ....... 
    </ul> 
    </div> 

을 My Watir 스크립트는 다음과 같습니다.


def getContactCount(browser, outputfile) 
     iframe_chat = browser.iframe(:src => "/tribe/connectionlist/index.html#appId/3") 
     ul_conns = iframe_chat.div(:id => "connectionList").div(:id => "connectionListItems").ul(:class => "connections") 
     numGroups = ul_conns.lis(:class => /group/).length 
     outputfile.puts "- Contact count -- total groups: " + numGroups.to_s 
     grpName = Array.new 
     ul_conns.lis(:class => /group/).each { |li| grpName.push li.data_name } 
     for igrp in 1..numGroups 
     list_grp = ul_conns.li(:data_name => grpName[igrp-1]) 
     outputfile.puts "  Group " + list_grp.text 
     list_grp.click 
     outputfile.puts "  Number of contacts found: " + ul_conns.lis(:class => "connection").length.to_s 
     ul_conns.lis(:class => "connection").each { |li| outputfile.puts "  " + li.span(:class => "name").text } 
     list_grp.click 
     end 
    end 

그리고 이것은 출력 :


- Contact count -- total groups: 3 
    Group SUGAR (0/11) 
    Number of contacts found: 11 
     (GFI) Joachim 
     (ICAP) Kissel 
     (JB Drax) James 
     (JB Drax) Simon 
     (JPM) Jason 
     (JPM) Jeb 
     (JSG) Steven 
     (Macq) NY SB Desk 
     (NE) Chris 
     (RJO) Babe 
     (RJO) Croce 
    Group Desk Connections (1/88) 
    Number of contacts found: 55 
     ICM_am 
     (ABN) Alex 
     (ABN) James 
     (ABN) Justin 
     (ADM) Marie 
     (Alliance) Victor 
     (Arfinco) Bruno 
     (Arfinco) Nico 
     ....... 
    Group Default (0/118) 
    Number of contacts found: 54 
     (ABN) James 
     (ABN) Justin 
     (ABN) Matt 
     ...... 

문제는 그룹 "데스크 연결"및 "기본"를 들면, 접점의 부분에 의해 검색된 스크립트 (55 of 88, 54 of 118, repectively).

사실, Chrome 브라우저에서 HTML 소스를 확인할 때 일부만 표시되었습니다. 그러나 프레임을 아래로 스크롤하면 더 많은 것들이 보였습니다 (그러나 위에있는 것들은 보이지 않게되었습니다).

누구든지 살펴보고 도움을 줄 수 있습니까? 모든 "li"(클래스 = "연결")을 얻으려면 어떻게해야합니까?

추가 정보가 필요한지 알려주세요.

고마워요.

+0

이 페이지의 HTML처럼 들리는거야/당신이 아래로 프레임을 스크롤 할 때 DOM이 업데이트 될 때, 그래서 모든 LIS를 :

(나는 테스트 페이지없이 추측하고있다하지만) 당신이해야 할 일 약이다 당신이 그들을 참조 할 때 존재하지 않는 당신이 원하는. –

+0

해결책이 있습니까? – xman

+0

프레임이 어떻게 스크롤됩니까? 그것은 단지 일반적인 스크롤바입니까? –

답변

0

문제를 푸는 열쇠는 프레임을 스크롤하는 것입니다. 이렇게하면

browser.frame(:id => 'frame_id).elements.last.wd.location_once_scrolled_into_view 

은 이론적으로, 그것은로드 요소의 다음 세트의 원인이됩니다 (나머지는 사라) : 다음을 사용하여 프레임의 끝 (즉, 마지막 요소)에 스크롤 할 수 있습니다.

한 번에 한 페이지의 결과 만 볼 수 있으므로 결과를 캡처하고 아래로 스크롤 한 다음 목록이 다시로드 될 때까지 기다린 다음 더 많은 결과를 캡처해야합니다.

# Get the results of your first 'page' 
results = iframe_chat.lis.collect(&:text) 

# Scroll to the bottom to get more results 
iframe_chat.elements.last.wd.location_once_scrolled_into_view 

# Wait for the list to refresh 
# I am checking that the last li disappears. 
# You may need to check for something to appear as well. 
iframe_chat.li(:text => results.last).wait_while_present 

# Get the results of your second 'page' 
results = iframe_chat.lis.collect(&:text) 
+0

작동 방식 : 'igrp in 1..numGroups' 'ul_conns.lis (: class => "connection"). last.wd.location_once_scrolled_into_view' 고맙습니다. Justin. – xman

관련 문제