title: Selenium find element on a dynamic dropdown with scroll (Java)
body: <p>I'm playing around with selenium and just lately started to take a look at drop-downs and selecting elements.</p>
  
  <p>For learning Selenium I'm using following site:
  <a href="http://www.smartclient.com/smartgwt/showcase/?sc_selenium=true#featured_dropdown_grid_category" rel="nofollow">http://www.smartclient.com/smartgwt/showcase/?sc_selenium=true#featured_dropdown_grid_category</a></p>
  
  <p>There is a drop-down Grid on which I'm trying to locate an element.
  Since the drop-down is dynamic and has a scroll bar then I need to scroll down and locate an element.
  Can anyone give me hints how I can locate and select an element on such drop-down?
  Let's say I would like to select:</p>
  
  <pre><code>Item: contains "Envelopes"
  Unit: "EA"
  Unit Cost: gather then 0.2
  </code></pre>
  
  <p>Here is my code:</p>
  
  <pre><code>            By itemPicker = ByScLocator.xpath("/html/body/div[2]/div/div/div/div/div[1]/div[2]/div/div/div[4]/div[1]/div/div/div/div[1]/div/div/div/form/table/tbody[2]/tr[2]/td[2]/table/tbody/tr/td[1]");
              driver.findElement(itemPicker).click();
              WebDriverWait wait = new WebDriverWait(driver, 30);
              wait.until(ExpectedConditions.elementToBeClickable(itemPicker));
              driver.findElement(itemPicker).sendKeys();
  
              boolean find = false;           
                  while (!find) {
  
                      By menuItems = ByScLocator.xpath("//tr[contains(@id, \"isc_PickListMenu_\")]");
                      List&lt;WebElement&gt; all = driver.findElements(menuItems);
  
                      try {
                          //Verify if all elements still exists in DOM
                          for (WebElement element : all) {
                              element.findElements(By.tagName("td"));
                          }
                      } catch (StaleElementReferenceException e) {
                          all = driver.findElements(menuItems);
                      }
  
                      for (WebElement element : all) {
                          List&lt;WebElement&gt; columns = element.findElements(By.tagName("td"));                          
                          String currenlyProcessedItem = columns.get(0).getText();
                          if (currenlyProcessedItem.matches(".*Envelopes.*")) {
                              if (columns.get(1).getText().equals("Ea")) {
                                  if (Double.parseDouble(columns.get(2).getText()) &gt; 0.2) {
                                          find = true;
                                      element.click();
                                      break;
                                  }
                              }
                          }
                      }
  
                      if (find) { //load another set of list items
                              driver.findElement(By.id("isc_3N")).sendKeys(Keys.PAGE_DOWN);
                      }
  
  
          }
  </code></pre>
  
  <p>The problem is that I'm unable to scroll down the list and identify item I want to select.
  Also I don't know if my aproach is optimal.</p>