简体   繁体   中英

How to click on a same button multiple times using Selenium WebDriver with Java

I tried searching for this but had 0 luck with this. Here's my problem, on my webpage I have a button that at every click generates some data. I'm trying to automate this so Selenium could keep clicking on it for, say 50 times, after every 2 seconds and I can verify that the data is being generated correctly. How do I formulate my for loop to achieve this. Help is greatly appreciated.

Here's a sample:

for (int i = 0; i < 50; i++){
 //click the button
  driver.findElement(By.xpath(xpath).click();
 //wait 2 seconds
  Thread.sleep(2000);
  //check that data is being generated correctly
  ...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM