title: How to click on an element from select using the label name - selenium java
body: <p><a href="https://i.stack.imgur.com/4Gsj9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4Gsj9.png" alt="enter image description here"></a></p>
  
  <pre><code>&lt;div class="left"&gt;
  &lt;select id="hidebox" class="ays-ignore" size="8"&gt;
  &lt;ul&gt;&lt;option value="103249"&gt;260 - OMAHA 30TH ST&lt;/option&gt;&lt;/ul&gt; 
  &lt;ul&gt;&lt;option value="103266"&gt;540 - UNION CITY&lt;/option&gt;&lt;/ul&gt;
  &lt;ul&gt;&lt;option value="3"&gt;800 - BETHLEHEM&lt;/option&gt;&lt;/ul&gt;
  &lt;ul&gt;&lt;option value="103271"&gt;430 - DALLAS SOUTH&lt;/option&gt;&lt;/ul&gt;
  &lt;ul&gt;&lt;option value="103270"&gt;410 - DALLAS&lt;/option&gt;&lt;/ul&gt;
  &lt;ul&gt;&lt;option value="100966"&gt;530 - TRACY&lt;/option&gt;&lt;/ul&gt;
  &lt;ul&gt;&lt;option value="103272"&gt;420 - FORT WORTH&lt;/option&gt;&lt;/ul&gt;
  &lt;ul&gt;&lt;option value="97224"&gt;820 - QUAKERTOWN&lt;/option&gt;&lt;/ul&gt;
  &lt;ul&gt;&lt;option value="103324"&gt;520 - SACRAMENTO&lt;/option&gt;&lt;/ul&gt;
  &lt;/select&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Hello,
  I'm trying click on an element based on the label "820 - QUAKERTOWN" and my approach is either incorrect or im missing something cause when i step thru, i see the entire list being returned but the required value is not clicked. The xpath is correct and appears to return the correct list of records, but the click is not being applied. My apologies if I use the wrong verbiage im new to Selenium and Java.
  I excluded the driver and get() website code, those lines were not revelant to my question. Please suggest other ideas if im using the wrong approach. I somewhat hit the wall.</p>
  
  <p>My expectation is that the row can be clicked using the label text such as "800 - BETHLEHEM" or any other from list. I did try the unique xpath approach and it worked, but my test fails when I run it against other environments where the option value is different.</p>
  
  <p>Thank you for any help y'all can provide.
  Example from a successful clicked when I used a unique xpath which I rather not used because of the environment reason.</p>
  
  <p><a href="https://i.stack.imgur.com/CnV5B.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CnV5B.png" alt="enter image description here"></a></p>
  
  <pre><code>package com.usc.uscspace.test.customer;
  
  import org.junit.Assert;
  import org.openqa.selenium.By;
  import org.openqa.selenium.JavascriptExecutor;
  import org.openqa.selenium.WebElement;
  import org.testng.annotations.Test;
  
  import java.util.List;
  
  public class CreateTest extends AbstractTestClass {
  
      final static String legacyWarehouse = "800 - BETHLEHEM";
  
  
      @Test
      public void createCustomerTest() {
          List&lt;WebElement&gt; pushWhseList = driver.findElements(By.xpath(".//*[@id='hidebox']"));
  
          int total_node = pushWhseList.size();
  
          for (int i = 0; i &lt; total_node; i++) {
              String list = pushWhseList.get(i).getText();
              if (list.contains(legacyWarehouse)) {
                  pushWhseList.get(i).click();
                  break;
              }
          }
      }
  
  }
  </code></pre>