Loop to fill in an input with various data - Selenium WebDriver

1

How to make a loop to scan an array and bring its data one by one and fill in the input?

The image illustrates well the problem ... I need For For to pass several times through the method and get the data from it and fill in the input and follow the normal flow of automation.

I get the input from the method data:

driver.findElement(By.xpath("/html/body/center/table/tbody/tr[2]/td[2]/form/table[3]/tbody/tr[17]/td/input[1]")).sendKeys(offers());

I click on filtering the data for it popular TextArea :

driver.findElement(By.xpath("/html/body/center/table/tbody/tr[2]/td[2]/form/table[3]/tbody/tr[17]/td/input[2]")).click();

I select the populated data in textArea :

Select selecionapermanenciamulta = new Select(driver.findElement(By.xpath("/html/body/center/table/tbody/tr[2]/td[2]/form/table[3]/tbody/tr[19]/td/table/tbody/tr/td[1]/select")));
        selecionapermanenciamulta.selectByIndex(0);

Click the arrow to take it to the other side:

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

Vector with data:

public static String offers (){
            List<String> offrers = new ArrayList<String>();    

            offrers.add ( "dados");
            offrers.add ( "dados");
            offrers.add ( "dados" );

            Collections.shuffle ( offrers );   

            return offrers.get(0);
        }

    
asked by anonymous 01.10.2015 / 14:22

1 answer

1

I do not know if I understood 100% what you want, but what I think you want is this:

List<String> testes = new List<String>();
testes.add("teste1");
testes.add("teste2");
testes.add("teste3");
Input textbox = new Input(driver.findElement(By.xpath("/html/body/center/table/tbody/tr[2]/td[2]/form/table[3]/tbody/tr[17]/td/input[1]")));
Input input1 = new Input(driver.findElement(By.xpath("/html/body/center/table/tbody/tr[2]/td[2]/form/table[3]/tbody/tr[17]/td/input[2]")));
Input input2 = new Input(driver.findElement(By.xpath("/html/body/center/table/tbody/tr[2]/td[2]/form/table[3]/tbody/tr[19]/td/table/tbody/tr/td[2]/input[1]")));
Select selecionapermanenciamulta = new Select(driver.findElement(By.xpath("/html/body/center/table/tbody/tr[2]/td[2]/form/table[3]/tbody/tr[19]/td/table/tbody/tr/td[1]/select")));
for(String teste: testes){
    textbox.sendKeys(teste);
    input1.click();
    selecionapermanenciamulta.selectByIndex(0);
    input2.click();
}

Notice that I removed your offers method, since it always started a test list and returned the first element of that list, after it has been scrambled. I imagine this will solve your problem.

    
01.10.2015 / 19:37