title: How to select items from drop down menu using Selenium?
body: <p>I have been trying to automate a search using Selenium. I simply want to search terms (say <code>Pink Floyd</code>) but the file type should be pdf. Here is what I have done so far:  </p>
  
  <pre><code>    //Query term
      WebElement element = driver.findElement(By.name("as_q"));
      String finalQuery = "pink floyd";
      element.sendKeys(finalQuery);
  
      //File type selection
      WebElement elem = driver.findElement(By.id("as_filetype_button"));
      elem.sendKeys("Adobe Acrobat pdf (.pdf)");
      driver.findElement(By.xpath("/html/body/div[1]/div[4]/form/div[5]/div[9]/div[2]/input[@type='submit']")).click();
  </code></pre>
  
  <p>This puts the term in the appropriate place and the drop down for file types are expanded but pdf option is not selected. Any help?</p>
  
  <p>I am using Selenium 2.53.0.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>The following code segment perfectly worked as per the accepted answer for this question. However, all on a sudden the code segment is not working. I am a bit surprised to find this out. Previously, I was able to select PDF automatically with the following code segment but now, nothing gets selected. </p>
  
  <pre><code> WebElement element = driver.findElement(By.name("as_q"));
   String finalQuery = "pink floyd";
   element.sendKeys(finalQuery);
   driver.findElement(By.id("as_filetype_button")).click();
   driver.findElement(By.xpath("//li[@class=class-name][@value='pdf']")).click();
  </code></pre>