title: Selenium webdriver: finding all elements with similar id
body: <p>I have this xpath: <code>//*[@id="someId::button"]</code></p>
  
  <p>Pressing it shows a dropdown list of values.</p>
  
  <p>Now, I know all the elements in the list have an id like this :</p>
  
  <pre><code>//*[@id="someId--popup::popupItemINDEX"]
  </code></pre>
  
  <p>, where INDEX is a number from 1 to whatever the number of options are.</p>
  
  <p>I also know the value which I must click.</p>
  
  <p>One question would be: since I will always know the id of the button which generates the dropdown, can I get all the elements in the dropdown with a <strong>reusable</strong> method? (I need to interact with more than one dropdown)</p>
  
  <p>The way I thought about it is:
  get the root of the initial ID, as in: </p>
  
  <pre><code>//*[@id="someId 
  </code></pre>
  
  <p>then add the rest : <code>--popup::popupItem</code>. I also need to add the index and I thought I could use a try block (in order to get though the exceptions when I give a bigger than expected index) like this:</p>
  
  <pre><code> for(int index=1;index&lt;someBiggerThanExpectedNumber;index++){
       try{
           WebElement aux= driver.findElement(By.xpath(builtString+index+"\"]"));
           if(aux.getText().equals(myDesiredValue))
               aux.click();
       }catch(Exception e){}
   }
  </code></pre>
  
  <p>Note that I am using the webdriver api and java.</p>
  
  <p><em><strong>I would like to know if this would work and if there is an easier way of doing this, given the initial information I have.</em></strong></p>
  
  <p>EDIT: The way I suggested works, but for an easier solution, the accepted answer should be seen</p>