Loop to fill an input with multiple data - Selenium Webdriver

Asked

Viewed 1,631 times

1

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

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

Get popular input with 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 to filter the data for it to popular the 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 data populated 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);

I click the arrow to take him 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 the 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);
        }

Imagem

  • 1

    I didn’t quite understand your doubt, but it’s making a for to repeat these steps that you have placed?

  • @Felipeavelar how do I do this for? I’m having this difficulty, I’m new in programming.

  • 1

    About which vector you want to iterate?

  • @Felipeavelar yes Elipe, the data are in offers(), I will edit the question and put it there.

1 answer

1


I don’t know if I understand 100% what you want, but what I think you want is the following:

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 I’ve removed your method offers, since he always started a test list and returned the first element of that list, after shuffling it. I imagine that solves your problem.

  • 1

    And this variable offers, I need to create it? for(String test: offers), this giving this error: offers cannot be resolved to a variable

  • @Pauloroberto, this was a mistake, at the time I forgot to change the variable, it should be testes instead of ofertas.

  • It didn’t work, It passes a single time, and then the Selenium gets lost, says it did not locate a certain element (the input, where it should play the next value), even though it is there.

  • Try to save the findElement in a variable, made an edit, see if it solves.

  • still gives the same error!

  • You can put the bug here?

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.