Skip to content Skip to sidebar Skip to footer

How To Click The Same Button More Than 50 Times In Protractor?

How to click the same button more than 50 times by using loop statement in protractor? Will protractor support this action? Here's my locator : var nudge= element(by.xpath('//a[@cl

Solution 1:

You can try simple for loop in javascript:

var nudge= element(by.xpath("//a[@class='isd-flat-icons fi-down']"));

for (i = 0; i < 50; i++) { 
    nudge.click();
}

The above script will click the button exactly 50 times. Before implementing this script consider:

  • The above script will click the button as fast as possible
  • Some sites can become unresponsive after even such small load

Solution 2:

You can also do this through the browser actions (should be better performance-wise, since actions are sent in a single command when you "perform" them):

var nudge = $("a.isd-flat-icons.fi-down");

var actions = browser.actions();
for (i = 0; i < 50; i++) { 
    actions = actions.click(nudge);
}
actions.perform();

Note that, if you want to introduce a delay between every click action, you can do that by having a custom "sleep" browser action:

var nudge = $("a.isd-flat-icons.fi-down");

var actions = browser.actions();
for (i = 0; i < 50; i++) { 
    actions = actions.click(nudge).sleep(500);
}
actions.perform();

The $ here is a shortcut for the "by.css" locator, which would be, generally speaking and according to the Style Guide, a better choice when using an XPath location technique.


Post a Comment for "How To Click The Same Button More Than 50 Times In Protractor?"