在量角器中迭代WebElements

时间:2018-10-29 10:01:31

标签: protractor

我是量角器的新手,我想存储WebElements(多个元素)。 然后迭代这些元素并编写该元素的文本。

describe("To test Protractor demo calculator", function() {
  beforeEach(function() {
    browser.get("https://juliemr.github.io/protractor-demo/");
  })
  var firstNumber = element(by.model("first"));
  var secondNumber = element(by.model("second"));
  var goButton = element(by.id("gobutton"));
  var history = element.all(by.repeater("//tr[@ng-repeat='result in memory']/td[3]"));
  function add(a, b) {
    firstNumber.sendKeys(a.toString());
    secondNumber.sendKeys(b.toString());
    goButton.click();
  }
  it("Add 2 numbers", function() {
    var numbers = [1, 2, 3, 4, 5];
    var i;
    for (i = 0; i < numbers.length - 1; i++) {
      add(numbers[i], numbers[i + 1]);
      console.log(numbers[i]);
    }
    // Method I'm used to iterate the elements. Code doesn't enter into the loop
    history.each(function(element) {
      console.log("Entered into loop")
      return element.getText().then(function(text){
        console.log(text);
      });
    })
  })
})

0 个答案:

没有答案