在java中调用相同的方法500次

时间:2014-09-26 08:22:20

标签: java selenium

嗨我需要调用方法“loop()”500次。我需要写“loop();” 500次或有多少方法可以多次调用它。请帮忙。以下代码在java中,我使用selenium webdriver。

public class Salesforce_login {
public static WebDriver driver;

public static void main(String[] args) throws InterruptedException {

    System.setProperty("webdriver.chrome.driver",
            "C:/Users/Master/Desktop/chromedriver.exe");
    driver = new ChromeDriver();
    // driver = new FirefoxDriver();

    Thread.sleep(1000);
    // driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

    driver.get("https://login.com");
    driver.findElement(
            By.xpath(".//*[@id='loginSwitcher:loginSwitcherForm']/div[1]/div[1]/div/a"))
            .click();
    Thread.sleep(1000);
    driver.findElement(By.xpath(".//*[@id='username']")).sendKeys(
            "*****");
    driver.findElement(By.xpath(".//*[@id='password']")).sendKeys(
            "*****");
    driver.findElement(By.xpath(".//*[@id='Login']")).click();
    Thread.sleep(30000);
    driver.findElement(By.xpath(".//*[@id='moreGroupMembersLink']"))
            .click();
    Thread.sleep(1000);
    loop();
    loop();
    loop();
    loop(); 


}
    public static void loop() throws InterruptedException{
    for (int i = 1; i < 25; i++) {
        System.out.println(driver
                .findElement(
                        By.xpath(".//*[@id='groupMembersDialogContent']/div/div[1]/div[2]/div/table/tbody/tr["+i+"]/td[2]/div/a"))
                .getAttribute("href"));
    }
        driver.findElement(By.xpath(".//*[@id='groupMembersDialogContent']/div/div[1]/div[3]/div/span[2]/span[1]/a")).click();
        Thread.sleep(2000);
    }
}

1 个答案:

答案 0 :(得分:3)

for(int i = 0; i < 500; i++) {
      loop();
}