title: How to keyPress + click with selenium
body: <p>I have a problem with my Selenium code not performing correctly the keyPress + click operation.</p>
  
  <p>The test should open the jqueryui.com link and select the first 2 li elements on the page.</p>
  
  <p>I am using Selenium 2.23 and Firefox 10. My code is as follows (I have trie 4 different ways to get it working but none performed):</p>
  
  <blockquote>
    <p>FirefoxProfile profile = new FirefoxProfile();</p>
    
    <p>profile.setEnableNativeEvents(true);
     WebDriver browser = new FirefoxDriver(profile);
     browser.get("<a href="http://jqueryui.com/demos/selectable/" rel="nofollow">http://jqueryui.com/demos/selectable/</a>");</p>
    
    <p>List elements = browser.findElements(By.cssSelector("ol#selectable li"));</p>
  
  <pre><code> Actions a = new Actions(browser);      
   a.keyDown(Keys.CONTROL)
   .moveToElement(elements.get(0))
   .click()
   .moveToElement(elements.get(1))
   .click()
   .keyUp(Keys.CONTROL)
   .build()
   .perform();
  
      Keyboard keyboard = ((HasInputDevices) browser).getKeyboard();
      keyboard.pressKey(Keys.CONTROL);
      List&lt;WebElement&gt; selectOptions = browser.findElements(By.cssSelector("ol#selectable li"));
      selectOptions.get(1).click();
      selectOptions.get(3).click();
      keyboard.releaseKey(Keys.CONTROL); 
  </code></pre>
  </blockquote>
  
  <pre><code>    Actions builder = new Actions(browser);
      builder.keyDown(elements.get(0), Keys.CONTROL)
          .click(elements.get(0))
          .click(elements.get(1))
          .keyUp(Keys.CONTROL);
      Action selectMultiple = builder.build();
      selectMultiple.perform();
  
      Robot robot = new Robot();
      robot.delay(1000);
      robot.keyPress(KeyEvent.CTRL_MASK);
      elements.get(0).click();
      elements.get(1).click();
      robot.keyRelease(KeyEvent.CTRL_MASK);
  
      browser.quit();
  </code></pre>
  
  <p>Can anyone help me with some other suggestions?</p>