Java 中的顺序数组列表 - Selenium WebDriver

Arraylist sequencial em Java - Selenium WebDriver

我有一个包含一些数据的数组列表,selenium 必须使用此数组列表中的数据完成一个字段,但顺序与它们在列表中的排列顺序相同。 目前他正在送元素,我需要他拿走元素1,等他回到运行之后拿走元素2,然后是元素3,依此类推。

如何让他按顺序排列元素。

package promocoes;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class criarPromocoes {

    public static void main(String[] args) {


         System.setProperty("webdriver.ie.driver", "C:/Users/paulo.roberto/Documents/eclipse/Selenium/IEDriverServer.exe");
          DesiredCapabilities caps = DesiredCapabilities.internetExplorer();
          caps.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
          WebDriver driver = new InternetExplorerDriver(caps);

          driver.get("url");
            driver.manage().window().maximize();

            //wait page
            WebDriverWait paginainicial = new WebDriverWait(driver, 10);  
            paginainicial.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("/html/body/center/table/tbody/tr[2]/td/form/table/tbody/tr[5]/td/table/tbody/tr/td/table/tbody/tr[1]/td[2]/input")));

            //login
            driver.findElement(By.xpath("/html/body/center/table/tbody/tr[2]/td/form/table/tbody/tr[5]/td/table/tbody/tr/td/table/tbody/tr[1]/td[2]/input")).sendKeys("login");
            driver.findElement(By.xpath("/html/body/center/table/tbody/tr[2]/td/form/table/tbody/tr[5]/td/table/tbody/tr/td/table/tbody/tr[2]/td[2]/input")).sendKeys("password");
            driver.findElement(By.xpath("/html/body/center/table/tbody/tr[2]/td/form/input[1]")).click(); 

            //wait page
            WebDriverWait presencanomePlano = new WebDriverWait(driver, 10);  
            presencanomePlano.until(ExpectedConditions.visibilityOfElementLocated(By.name("nomePromocao")));

            //form

            driver.findElement(By.name("nomePromocao")).sendKeys(nomePromocao());                               driver.findElement(By.name("dataInicioPromocao")).sendKeys("24/09/2015");               driver.findElement(By.name("dataFimPromocao")).sendKeys("04/12/2049");



    }


     public static String nomePromocao (){
            List<String> lista = new ArrayList<String>();


            lista.add ( "promo1" );             
            lista.add ( "promo2");
            lista.add ( "promo3");

            Collections.shuffle ( lista );   

            return lista.get(0);
        }


}

如果您的目标是使用列表中的随机值多次填写表单:

public static void main(String[] args) {

  ...

  //form, iterate over each promotion
  List<String> promocaoNames = getPromocaoNames();
  for(String promocaoName : promocaoNames){
    driver.findElement(By.name("nomePromocao")).sendKeys(promocaoName);
    driver.findElement(By.name("dataInicioPromocao")).sendKeys("24/09/2015");
    driver.findElement(By.name("dataFimPromocao")).sendKeys("04/12/2049");

    ...
  }

  ...
}


public static List<String> getPromocaoNames (){
  List<String> lista = new ArrayList<String>();
  lista.add("promo1");             
  lista.add("promo2");
  lista.add("promo3");

  Collections.shuffle ( lista );
  return lista;
}