title: webdriver wait for one of a multiple elements to appear
body: <p>Is there a way to get a <code>webDriverWait</code> to wait for one of a number of elements to appear and to act accordingly based on which element appears?</p>
  
  <p>At the moment I do a <code>WebDriverWait</code> within a try loop and if a timeout exception occurs I run the alternative code which waits for the other element to appear. This seems clumsy. Is there a better way? Here is my (clumsy) code:</p>
  
  <pre><code>try:
      self.waitForElement("//a[contains(text(), '%s')]" % mime)
      do stuff ....
  except TimeoutException:
      self.waitForElement("//li[contains(text(), 'That file already exists')]")
      do other stuff ...
  </code></pre>
  
  <p>It involves waiting an entire 10 seconds before it looks to see if the message that the file already exists on the system.</p>
  
  <p>The function <code>waitForElement</code> just does a number of <code>WebDriverWait</code> calls like so:</p>
  
  <pre><code>def waitForElement(self, xPathLocator, untilElementAppears=True):
      self.log.debug("Waiting for element located by:\n%s\nwhen untilElementAppears is set to %s" % (xPathLocator,untilElementAppears))
      if untilElementAppears:
          if xPathLocator.startswith("//title"):
              WebDriverWait(self.driver, 10).until(lambda driver : self.driver.find_element_by_xpath(xPathLocator))
          else:
              WebDriverWait(self.driver, 10).until(lambda driver : self.driver.find_element_by_xpath(xPathLocator).is_displayed())
      else:   
          WebDriverWait(self.driver, 10).until(lambda driver : len(self.driver.find_elements_by_xpath(xPathLocator))==0)
  </code></pre>
  
  <p>Anybody got any suggestions to accomplish this in a more efficient way?</p>