0
votes

I'm working with protractor and i'm doing a repeater, first I get the text and then i'm trying to do the click on that element but i'm getting an error

[14:40:00] E/launcher - roleSelected.element is not a function
[14:40:00] E/launcher - TypeError: roleSelected.element is not a function
    at role.element.getText.then (/Users/jburquez/akamai/ConsoleUI/tests/e2e/console_bdd/steps/manage_agents_steps.js:41:31)
    at elementArrayFinder_.then (/Users/jburquez/akamai/ConsoleUI/node_modules/protractor/built/element.js:804:32)
    at ManagedPromise.invokeCallback_ (/Users/jburquez/akamai/ConsoleUI/node_modules/selenium-webdriver/lib/promise.js:1376:14)
    at TaskQueue.execute_ (/Users/jburquez/akamai/ConsoleUI/node_modules/selenium-webdriver/lib/promise.js:3084:14)
    at TaskQueue.executeNext_ (/Users/jburquez/akamai/ConsoleUI/node_modules/selenium-webdriver/lib/promise.js:3067:27)
    at asyncRun (/Users/jburquez/akamai/ConsoleUI/node_modules/selenium-webdriver/lib/promise.js:2927:27)
    at /Users/jburquez/akamai/ConsoleUI/node_modules/selenium-webdriver/lib/promise.js:668:7
    at process._tickCallback (internal/process/next_tick.js:68:7)

This is the code

    var agentRoles = element.all(by.repeater('ctrl.roles'));
    agentRoles.each((role) => {
      return role.element(by.xpath(".//div[@class='md-whiteframe-1dp outset inset']/md-checkbox/div[2]/span")).getText()
      .then((roleSelected) => {
        if(agentRole == roleSelected){
          return roleSelected.element(by.xpath(".//div[@class='md-whiteframe-1dp outset inset']/md-checkbox/div")).click().isPresent();
        }
      });
    });

So not sure what should I do in this case, hope you can help!!

1

1 Answers

0
votes

roleSelected is a string and you are trying to loop another web element to the text.

   var agentRoles = element.all(by.repeater('ctrl.roles'));
    agentRoles.each((role) => {
      return role.element(by.xpath(".//div[@class='md-whiteframe-1dp outset inset']/md-checkbox/div[2]/span")).getText()
      .then((roleSelected) => {
        if(agentRole == roleSelected){
          return agentRole.element(by.xpath(".//div[@class='md-whiteframe-1dp outset inset']/md-checkbox/div")).click().isPresent();
        }
      });
    });

Hope the above script helps you