-1

I have 3 emails

String[] emails = {"x@gmail.com", "y@gmail.com", "z@gmail.com"}

I want the code to select x@gmail.com first, y@gmail.com second, and z@gmail.com third, and plug it into this command :

driver.findElement(By.xpath("//android.widget.EditText[@index='2']")).sendKeys(emails);

But how do I make it so it selects x@gmail.com first, y@gmail.com second, and z@gmail.com last?

noob
  • 1
  • 1
  • 8
  • [`for-each`-loop](https://docs.oracle.com/javase/1.5.0/docs/guide/language/foreach.html)? – Turing85 Jun 17 '19 at 20:57
  • start reading tutorials or search for this on SO.. plenty examples to find. I don't want to be sarcastic but this is noobish and you find the open door ***>[here](https://stackoverflow.com/questions/9329446/for-each-over-an-array-in-javascript)<*** ! – ZF007 Jun 17 '19 at 21:30
  • 1
    Possible duplicate of [For-each over an array in JavaScript?](https://stackoverflow.com/questions/9329446/for-each-over-an-array-in-javascript) – ZF007 Jun 17 '19 at 21:32

2 Answers2

1

By looping over each email address in emails and calling your method one after the other. I would use a for-each loop. Read it like for each String e in emails call the method sendKeys.

for (String e : emails) { 
    driver.findElement(By.xpath("//android.widget.EditText[@index='2']"))
        .sendKeys(e); 
}
Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249
0

You can use a comparator to sort them (that is if all emails are @gmail.com).

Arrays.sort(emails);

This would sort the array lexicographically and you can iterate over the array to get them from start - end

for (String email: emails){
    //Do your thing
}
static const
  • 953
  • 4
  • 16