I have one button which I need to use more than 10 times

I am new for mobile automation, please help for below.
I have one button which I need to use more than 10 times, may be 20 times or 30 times…
Can anybody help to writing a code.

You can use button.click(); in a for loop.

You may want to put a pause in there, in Ruby since you don’t specify:

button = find_element(name:, "button")
10.times do
  button.click
  sleep(2)
end

If you are using Java, you could use this loop:

WebElement buttonElement = driver.findElement(By.xpath(“xpath selector”));
int i;
for(i=0;i<=20;i++) {
buttonElement.click();
}

1 Like

that is a right thing u can use loop to click an element multiple times.
Can you share u r test case, not able to visualize anything why u want to click same element multiple times

There may be case you are clicking the element multiple times but preconditions got changed like

  1. page got refreshed
  2. u moved to new page which contains same element but here on this page also button xpath/name remains a same

if U want to make a WebElement common to all test cases in a class then you can declare it globally

@jellybeans, Thanks It worked.