Passing Protractor ElementFinder to deferred.fulfill() results in a promise containing a null value

后端 未结 1 1666
礼貌的吻别
礼貌的吻别 2021-01-21 11:18

I am calling deferred.fulfill() with a Protractor elementfinder as a parameter. When placing a breakpoint on the fulfill I can see that the elementfinder \"solutionElement\" is

相关标签:
1条回答
  • 2021-01-21 11:24

    I usually use the map, filter, action/assert pattern. It looks something like this:

    element.all(locator).map(function(elm, index) {
      // Get the value you are interested in finding and return the element too.
      return {
        elm: elm,
        text: elm.getText(),
        index: index
      };
    }).then(function(list) {
      // Find your text here. Otherwise fail.
      for(var i = 0; i<list.length; i++) {
        if(list[i].text === name) {
          return list[i].elm;
        }
      }
      throw new Error('Solution not found');
    }).then(function(elm) {
      // Perform an action on the element you found.
      elm.click();
    });
    

    Map will fully resolve all the promises before the results are passed to the next then in the chain.

    0 讨论(0)
提交回复
热议问题