2017-11-21 9 views
0

div에 대한 부모가 특정 클래스 (이 경우 "parent")를 갖고 있는지 확인하는 테스트를 작성해야합니다.각도기의 요소에서 상위 클래스를 가져 오는 방법은 무엇입니까?

.... 
<div class="parent"> 
    <div id="child"></div> 
</div> 
.... 

내가 시도 무엇 :

이 코드가 ..

element(by.id('child')).getWebElement().getDriver().getAttribute('class'); 

을하지만 다음과 같은 오류가 어떻게 계속하는 아무 생각이

.getWebElement(...).getDriver(...).getText is not a function 

답변

2

부모님을 제대로 얻지 못하고 있습니다. 그것은 XPath는이 작업을 수행하는 가장 쉬운 방법 :

이 예에서
element(by.id('child')).element(by.xpath('..')).getAttribute('class'); 

, by.xpath('..')는 부모 요소를 선택해야합니다.

+0

감사합니다. 완벽한 작품입니다! –

0

don't want to use xpath의 경우 논리를 되돌릴 수 있습니다. 이 browser 개체를 반환하기 때문에

let child = element(by.id('child')).getWebElement(); 
let parent = child.getDriver().findElement(by.tagName('div')); 
expect(parent.getAttribute('class')).toBe('parent'); 

getAttribute()

직접 getDriver() 작동하지 않습니다 :로

element(by.css('div.parent > div[id="child"]'))

1

당신은 당신의 코드를 조정할 수 있습니다.