0

I have three combo boxes present on the page and I have to click the third one and select options from it.

I have code for clicking random. please let me know how to modify this code to select third combo box.

List<WebElement> list = driver.findElements(By.cssSelector(".select2-selection__arrow"));
Random r = new Random();
int randomvalue = r.nextInt(list.size());
System.out.println(randomvalue);
list.get(randomvalue).click();
anatol
  • 791
  • 9
  • 16
Aditya
  • 457
  • 2
  • 8
  • 27
  • 1
    Please share the html. – Guy Feb 19 '17 at 08:12
  • If those 3 boxes are wrapped in separate containers, you can limit the scope to the third one and then select the combobox. Or you can use xpath. – peter pawar Feb 19 '17 at 08:31
  • No all the three are wrapped in a single container.... – Aditya Feb 19 '17 at 08:34
  • Not sure but you can try some thing like this : list[2].get(randomvalue).click(); – peter pawar Feb 19 '17 at 08:45
  • list[2].get(randomvalue).click () is not working .. the dropdown is not selected – Aditya Feb 19 '17 at 09:48
  • Possible duplicate of [Generating random integers in a specific range](http://stackoverflow.com/questions/363681/generating-random-integers-in-a-specific-range) – JeffC Feb 19 '17 at 23:10
  • The problem is that according to the docs, the max value is excluded. `nextInt(int n) Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence.` – JeffC Feb 19 '17 at 23:10
  • list.get(randomvalue).click(); --> list.get(2).click(); – MikeJRamsey56 Mar 12 '17 at 01:07

0 Answers0