2

enter code here

for (var i=1; i<8 ; i++)

 {
  var eleClick = element(by.xpath("//*[text()='Choices for Independence-Guidelines - 3705']"));

  eleClick.isPresent().then(function(result){
    if(result)
    {
      eleClick.click();
      browser.sleep(3000);
      console.log("Able to click");
         }
    else{
      var nextPage = element(by.xpath("//*[text()='Next']"));

      nextPage.click();

      browser.sleep(3000);
      console.log("Unable to click");
    }

  })

But when element is found it clicks the element 5 times. I have used break statement but it throws Illegal statement. Can someone please help.

closed as off-topic by dzieciou, Bharat Mane, NarendraC, Alexey R., NarendraR May 14 '18 at 11:37

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions about software development unrelated to testing are off-topic here, but can be asked on Stack Overflow." – dzieciou, Bharat Mane, NarendraC, NarendraR
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Please SHOW the code where you use the break. It is hard to diagnose why it isn't working if we can't see the code you are using ! This site will help you solve your problem but we don't just write the 'right' code for you. – Michael Durrant May 12 '18 at 12:05
  • There are so many issues on so many levels in this piece of code. I don't know where to start from and what to suggest. – Vishal Aggarwal May 12 '18 at 13:33
  • For starters, why do you need a loop here? – Vishal Aggarwal May 12 '18 at 13:56
  • What are you trying to test here? – demouser123 May 12 '18 at 16:19

Browse other questions tagged or ask your own question.