title: Select random element from the list in Selenium Java and click on it, but getAttribute is not equal to zero
body: <p>I'm trying to get random element from the list and click on it. The thing is, the elements are products which have attribute &quot;quantity&quot; and I want to click on the random element which quantity is not equal to zero. I'm using Selenium and Java.</p>
  <p>I tried to create two lists, one with all elements and the other to put elements which are not equals to zero and with Random class to click on element but to no avail, it does click on random element but sometimes hits the one with zero quantity.</p>
  <pre class="lang-java prettyprint-override"><code>    List&lt;WebElement&gt; products= driver.findElements(By.id(&quot;elementId&quot;));
      List&lt;Integer&gt; productsNotEqualToZero = new ArrayList&lt;&gt;();
  
      for(webElement:products){
      if(!webElement.getAttribute(&quot;quantity&quot;).equals(&quot;0&quot;)){
  
   
  productsNotEqualToZero.add(Integer.ParseInt(webElement.getAttribute(&quot;quantity 
      &quot;)))
      }
      }
      Random random = new Random();
      int result = random.nextInt(productsNotEqualToZero.size());
      products.get(result).click;
  </code></pre>
  <p>The problem is that nothing guarantees that product attribute &quot;quantity&quot; is not equals to zero.</p>