2015-01-07 2 views
3

다른 요소 다음에 요소를 가져올 수 있습니까? (하지 하위 요소)각도기 : 다음 태그를 얻는 방법

HTML 코드 :

<input id="first-input" type="text"/> 
<ul> 
    <li>1</li> 
    <li>2</li> 
</ul> 
<input id="second-input" type="text"/> 
<ul> 
    <li>1</li> 
    <li>2</li> 
</ul> 
<input id="third-input" type="text"/> 
<ul> 
    <li>1</li> 
    <li>2</li> 
</ul> 

는 어떻게 얻을 수 ulelement(by.id('second-input'))을 다음?

가 여기 내 이해입니다 : 내 경우

element(by.id('second-input')).element(by.tagName('ul')) // This doesn't work because this looks for sub-elements in <input id="second-input"> 
element.all(by.tagName('ul')).first() // This doesn't work because it gets the 'ul' following <input id="first-input"> 
element(by.id('second-input')).element.all(by.tagName('ul')) // This doesn't work because this looks for all 'ul' elements as sub-elements of <input id="second-input"> 

이 '의 고유 식별자, 또는 고유 아무것도하지 않습니다 UL. 한 번에

element(by.id('second-input')).element(by.xpath('following-sibling::ul')); 

또는 :

+0

고유 한 ID를 지정하십시오. 중첩되어 있지 않으므로 자바 스크립트가 함수를 이해하지 못합니다. –

+0

타사 라이브러리에서 UL을 생성했습니다. 나는 그것을 만지는 것을 원하지 않는다. 다른 옵션은 없습니까? – Jason

답변

7

당신은 ul 형제 다음 by.xpath()를 사용하고 을 요청할 수 있습니다

element(by.xpath('//input[@id="second-input"]/following-sibling::ul')); 

는 또 다른 옵션은 함께 by.css()을 사용하는 것입니다 adjacent sibling selector :

element(by.css('#second-input + ul'));