2016-06-22 1 views
0

페이지 객체 젬을 사용하여 ID로 정의 된 체크 박스 목록이 있습니다. 샘플은 다음과 같습니다.페이지 객체를 사용하여 일련의 체크 박스를 반복하는 방법은 무엇입니까?

checkbox  :main_product,      id:    '19437578_58659806' 
checkbox  :thumb_one,       id:    '19437579_58659811' 
checkbox  :thumb_two,       id:    '19437580_58659812' 
checkbox  :thumb_three,      id:    '19437581_58659813' 
checkbox  :thumb_four,      id:    '19437582_58659814' 
checkbox  :thumb_five,      id:    '19437583_58659815' 
checkbox  :thumb_six,       id:    '19437584_58659816' 
checkbox  :thumb_seven,      id:    '19437585_58659817' 
checkbox  :thumb_eight,      id:    '19437586_58659818' 
checkbox  :thumb_nine,      id:    '19437587_58659819' 
checkbox  :thumb_ten,       id:    '19437588_58659820' 
checkbox  :tt_one,       id:    '19437594_58659842' 
checkbox  :tt_two,       id:    '19437595_58659843' 
checkbox  :tt_three,       id:    '19437596_58659844' 
checkbox  :tt_four,       id:    '19437597_58659845' 
checkbox  :tt_five,       id:    '19437598_58659846' 
checkbox  :tt_six,       id:    '19437599_58659847' 
checkbox  :tt_seven,       id:    '19437600_58659848' 
checkbox  :tt_eight,       id:    '19437601_58659849' 
checkbox  :tt_nine,       id:    '19437602_58659850' 
checkbox  :tt_ten,       id:    '19437603_58659851' 

나는 그것을 본다. 특정 div 안에있는 모든 체크 박스 요소를 모으는보다 효율적인 방법이 있어야합니다. 내가 방법을 찾고 있어요

은 본질적으로

checkbox_objects.each do |checkbox| 
    checkbox.check 
end 

을 할 수 그러나 나는 checkbox_objects를 정의하는 방법을 모르겠어요. 특정 요소 안에있는 모든 확인란을 모아서 배열에 넣을 수있는 방법을 아는 사람이 있습니까? 미리 감사드립니다.

답변

2

과 대조적으로 checkboxes 접근 방식은 의 확인란을 만드는 데 사용됩니다. 당신은 모든 체크 박스를 찾아 블록을 지정할 수

<div id="other"> 
    <input type="checkbox"> 
    <input type="checkbox"> 
</div> 
<div id="container"> 
    <input type="checkbox"> 
    <input type="checkbox"> 
</div> 

div ID로 "용기"를 말한다 : 페이지의 HTML을 가정

같이 구성되어

checkboxes(:thumb) { div_element(id: 'container').checkbox_elements } 

또는, 당신은 찾을 수 있습니다 CSS 선택기 또는 XPath가 더 간결합니다.

checkboxes(:thumb, css: 'div#container input[type="checkbox"]') 

page.thumb_elements.each do |checkbox| 
    checkbox.check 
end 

또는 한 - 라이너 :

page.thumb_elements.each(&:check) 
님, 페이지 개체가 일치 확인란을 반환하는 <name>_elements 방법을 얻는다
관련 문제