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[@class='isd-flat-icons fi-down']"));
nudge.click();
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[@class='isd-flat-icons fi-down']"));
nudge.click();
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:
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.