How to have WebDriverWait return element instead of boolean in Python using Selenium
Question: Right now, I have a method that will wait until an element is visible using:

    
    
    WebDriverWait(self.driver, seconds).until(lambda s: s.find_element_by_xpath(path).is_displayed())
    

This works properly; however, it returns a boolean, rather than the element
that it found. I would like it to return that element once it is found. I am
doing this with the following:

    
    
    def waituntil(path, seconds):
        WebDriverWait(self.driver, seconds).until(lambda s: s.find_element_by_xpath(path).is_displayed())
        ret = self.driver.find_element_by_xpath(path)
        return ret
    

Sure, this works. Unfortunately, it requires Selenium to find the same element
twice, though, which adds waiting time (no matter how small). Is there a way I
can return a web element using a waituntil (or similar functionality) by
finding an element only once? So something that would allow the following:

    
    
    ret = WebDriverWait(self.driver, seconds).until(lambda s: s.find_element_by_xpath(path).is_displayed())
    ret.click()
    

I'm currently using:

    
    
    Python 2.7
    Windows 7
    Selenium 2.4.4
    Firefox 35.0.1
    


Answer: Use
`selenium.webdriver.support.expected_conditions.presence_of_element_located`.

Based on [the unofficial docs](http://selenium-
python.readthedocs.org/waits.html):

    
    
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions
    ret = WebDriverWait(self.driver, seconds).until(
        expected_conditions.presence_of_element_located((By.XPATH, path)))
    ret.click()
    

(Left out other imports and initialization for clarity, since you seem to have
that stuff working. See the earlier link if you're running into issues.)

