title: Selecting a random option from a dropdown list
body: <p>I need to select a random option from a dropdown list. My understanding is that I need to count the number of available options, then select a random index between 0 and the number of available options. </p>
  
  <p>So far I have this -</p>
  
  <pre><code>public static void selectRandomIndexDropdown(this IWebDriver driver, By elementName)
  {
      var element = driver.FindElement(elementName);
      element.selectRandomIndexDropdown();
  }
  
  public static void selectRandomIndexDropdown(this IWebElement element)
  {
      if (element == null || element.TagName.ToLower() != "select")
          return;
  
      int indexCount = element.FindElements(By.TagName("option")).Count();
      new SelectElement(element).SelectByIndex(Rnd.Next(0, indexCount));
  }
  </code></pre>
  
  <p>And trying to call it -</p>
  
  <pre><code>driver.selectRandomIndexDropdown(By.XPath("//*[@id='ASPxGridViewDeskFees_DXEFL_DXEditor1_I']"));
  </code></pre>
  
  <p>This doesn't seem to work. No errors displayed or exceptions thrown, looks as though the code executes but just does not click on an option within the list. Any ideas?</p>