title: How do I open a list and select an option in Selenium WebDriver when Select and WebElement do not work
body: <p>I'm new to Java and Selenium WebDriver. To learn how to use WebDriver, I decided to automate the flight booking process on the Emirates website. I've had problems but now I'm truly stuck. When I'm entering in my flight details, prior to selecting a flight, and I decide on leg two, of an advanced journey, to travel "First Class", I cannot figure out how to automate this process - the same applies to increasing the number of adult passengers. I haven't included the html here but it can be found when inspecting the elements in the lists. </p>
  
  <p>So the code that works is this:</p>
  
  <pre><code>    WebDriver driver = new ChromeDriver();
  
     // This opens the browser on the Emirates homepage
      driver.get("http://www.emirates.com/uk/english/");
  
      // Opening main menu item "Book"
      driver.findElement(By.xpath("//li[@id='book']/a/span")).click();
  
      // For the second leg of the flight, I wish to travel first class &gt;
      // therefore I open the drop down and select "First 
      driver.findElement(By.id("ctl00_c_CtWNW_flightClass1_chosen")).click();
  </code></pre>
  
  <p>However, I cannot work out how to select "First Class" and have this appear as the class I would like to travel as, and proceed with the booking. Can anyone help?</p>
  
  <p>This is taken from FirePath (Xpath displayed):</p>
  
  <pre><code>&lt;li id="option_id_ctl00_c_CtWNW_flightClass1_chosen_2" class="active-result" style="" data-option-array-index="2" text="First Class" role="option" aria-selected="false" tabindex="-1"&gt;
  </code></pre>
  
  <p>When I right click on First Class from the combo box</p>
  
  <p>And the html from the div:</p>
  
  <pre><code>&lt;div id="ctl00_c_CtWNW_flightClass1_chosen" title="Select your preferred cabin class for your inbound flight. - Selected: First Class" style="width: 100%;" class="chosen-container chosen-container-single chosen-container-single-nosearch"&gt;&lt;a aria-expanded="false" title="Select your preferred cabin class for your inbound flight. - Selected: First Class" class="chosen-single" role="combobox" tabindex="0"&gt;&lt;em aria-live="polite" class="visually-hidden"&gt;Selected: First Class&lt;/em&gt;&lt;span class="cabin-class_3" aria-hidden="true"&gt;First Class&lt;/span&gt;&lt;div&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;/a&gt;&lt;div class="chosen-drop" aria-hidden="true"&gt;&lt;div class="chosen-search" aria-hidden="true"&gt;&lt;label class="label-hidden" for="chosenLabel1"&gt;Label&lt;/label&gt;&lt;input aria-activedescendant="option_id_ctl00_c_CtWNW_flightClass1_chosen_0" readonly="" id="chosenLabel1" autocomplete="off" placeholder="Input a value to search" style="display: none;" type="text"&gt;&lt;/div&gt;&lt;ul class="chosen-results" tabindex="-1"&gt;&lt;li tabindex="-1" aria-selected="false" role="option" text="Economy Class" id="option_id_ctl00_c_CtWNW_flightClass1_chosen_0" data-option-array-index="0" style="" class="active-result"&gt;&lt;span style="display: inline;float:none;"&gt;Economy Class&lt;/span&gt;&lt;/li&gt;&lt;li aria-selected="false" role="option" text="Business Class" id="option_id_ctl00_c_CtWNW_flightClass1_chosen_1" data-option-array-index="1" style="" class="active-result"&gt;&lt;span style="display: inline;float:none;"&gt;Business Class&lt;/span&gt;&lt;/li&gt;&lt;li tabindex="-1" aria-selected="true" role="option" text="First Class" id="option_id_ctl00_c_CtWNW_flightClass1_chosen_2" data-option-array-index="2" style="" class="active-result result-selected"&gt;&lt;span style="display: inline;float:none;"&gt;First Class&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;/div&gt;
  &lt;a aria-expanded="false" title="Select your preferred cabin class for your inbound flight. - Selected: First Class" class="chosen-single" role="combobox" tabindex="0"&gt;&lt;em aria-live="polite" class="visually-hidden"&gt;Selected: First Class&lt;/em&gt;&lt;span class="cabin-class_3" aria-hidden="true"&gt;First Class&lt;/span&gt;&lt;div&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;/a&gt;
  &lt;em aria-live="polite" class="visually-hidden"&gt;Selected: First Class&lt;/em&gt;
  &lt;span class="cabin-class_3" aria-hidden="true"&gt;First Class&lt;/span&gt;
  </code></pre>
  
  <p><a href="http://i.stack.imgur.com/jnv4Q.png" rel="nofollow">The image shows the output from Firepath after clicking on First Class, in the console</a></p>