title: How loop drop down value using Selenium JAVA
body: <p>I have a dropdown with some countries as follows,   </p>
  
  <p><a href="https://i.stack.imgur.com/Zyfih.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Zyfih.jpg" alt="enter image description here"></a></p>
  
  <p>I want to send the values US,CA,AF,AL,DZ,AS,AD to an array, loop it and print by using Selenium and Java.</p>
  
  <p>I tried the following</p>
  
  <pre><code>WebElement elementdrop = d.findElement(By.xpath("path"));
  List&lt;WebElement&gt; dropdownvalues = d.findElements(By.xpath("path"));
  for(WebElement value:dropdownvalues)
  { 
    String pcvalues=value.getText();
    System.out.println("value names" + pcvalues);
   }
  </code></pre>
  
  <p>This will print United States Canada Afghanistan Albania etc. But I want like US CA AF AL DZ AS AD</p>