title: Locate only non-hidden elements using Selenium WebDriver in C#
body: <p>I have a collection of records on a web page, and when a record is clicked, a 'Delete' link is displayed (actually 'unhidden' as its actually always there).</p>
  
  <p>When trying to access this 'Delete' link, I am using its value.</p>
  
  <p>When I use <code>Driver.FindElement</code>, it returns the <em>first</em> Delete link, even though it's hidden, and therefore can't click it (and shouldn't as it is not the right link).</p>
  
  <p>So, what I basically want to do is find only <em>non-hidden</em> links. The code below works, but as it iterates through every Delete link I am afraid it may be inefficient. </p>
  
  <p>Is there a better way?</p>
  
  <pre><code>public class DataPageModel : BasePageModel
  {
      private static readonly By DeleteSelector = By.CssSelector("input[value=\"Delete\"]");
  
      private IWebElement DeleteElement
      {
          get
          {
              var elements = Driver.FindElements(DeleteSelector);
              foreach (var element in elements.Where(e =&gt; e.Displayed))
              {
                  return element;
              }
              Assert.Fail("Could not locate a visible Delete Element");
              return null;
          }
      }
  }
  </code></pre>