Sandeep Raulo
Sandeep Raulo

Reputation: 154

Access Child elements in Protractor

I'm trying to access text attribute of child element but every time getting null value. The DOM looks like as below

<div ng-repeater='abc'>
    <span class='xyz'>Mango</span>
</div>
<div ng-repeater='abc'>
    <span class='xyz'>Apple</span>
</div>

I have tried below code:

   var parent = element(by.repeater('abc'));
    var child = parent.all(by.xpath('//span[@class="xyz"]'));

    for (let index = 0; index < parent.count(); index++) {
      console.log("Value" + child.getText());
    }

All the time im getting the error as Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.

I have already tried increasing the timeout to 30seconds and the page is loading properly with no sync issues but still getting the error.

any help will be appreciated.

Upvotes: 0

Views: 448

Answers (1)

yong
yong

Reputation: 13712

element.all(by.repeater('abc')).getText().then(function(txts){
   txts.forEach(function(txt){
      console.log(txt);
   })
})

// the `getText()` api will get visible text of all descendants of current element, 
// that's why parent node `div` can get the text on child node `span`

Upvotes: 2

Related Questions