title: How to find an Element by index in selenium webdriver for java
body: <p>Im trying to automate the Google Images page:</p>
  
  <p><a href="https://www.google.com/search?q=pluralsight&amp;biw=1416&amp;bih=685&amp;source=lnms&amp;tbm=isch&amp;sa=X&amp;ei=qGd6VN6bEZTooAT7q4C4BQ&amp;sqi=2&amp;ved=0CAgQ_AUoAw" rel="nofollow">https://www.google.com/search?q=pluralsight&amp;biw=1416&amp;bih=685&amp;source=lnms&amp;tbm=isch&amp;sa=X&amp;ei=qGd6VN6bEZTooAT7q4C4BQ&amp;sqi=2&amp;ved=0CAgQ_AUoAw</a></p>
  
  <p>All the images have the same class but no id and the results are constantly changing.  So I would like to be able to click on the images based on their index.</p>
  
  <p>I know how to do it in C#...but I cant figure out how to specify in the index in Java.  When I try to select an index beyond 0, I get and IndexOutOfBounds error, but i cant figure out why</p>
  
  <pre><code>WebElement image = chromeDriver.findElement(By.className("rg_di"));
  WebElement imageLink = image.findElements(By.tagName("a")).get(1);
  imageLink.click();
  </code></pre>
  
  <p>Here is the entire code im using...any help would be appreciated:</p>
  
  <pre><code>    System.setProperty("webdriver.chrome.driver", "/Users/user/chromedriver");
      WebDriver chromeDriver = new ChromeDriver();
      chromeDriver.get("http://www.google.com");
  
      WebElement searchBox = chromeDriver.findElement(By.id("gbqfq"));
      searchBox.sendKeys("pluralsight");
      searchBox.sendKeys(Keys.RETURN);
  
      chromeDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
  
      WebElement imagesLink = chromeDriver.findElement(By.linkText("Images"));
      imagesLink.click();
  
      WebElement image = chromeDriver.findElement(By.className("rg_di"));
      WebElement imageLink = image.findElements(By.tagName("a")).get(1);
      imageLink.click();
  </code></pre>
  
  <p>Any help would be greatly appreciated</p>