title: Selenium, Presence of one of many elements located?
body: <p>Building off of the answer to <a href="https://stackoverflow.com/questions/26566799/how-to-wait-until-the-page-is-loaded-with-selenium-for-python#40037216">How to wait until the page is loaded with Selenium for Python?</a> I am attempting to create a method that allows multiple elements to be polled for presence using Expected Conditions. </p>
  
  <p>I receive an error <strong>'bool' object is not callable</strong> on the line containing: wait.until(any(expectations)). </p>
  
  <p>The thought process was to allow an number of Xpaths to be passed as expected conditions, then using <a href="https://docs.python.org/3/library/functions.html#any" rel="nofollow noreferrer">any()</a>, in a similar manner to this java based answer, <a href="https://stackoverflow.com/questions/45166181/trying-to-wait-for-one-of-two-elements-in-the-page-using-selenium-xpath">Trying to wait for one of two elements in the page using selenium xpath</a>, check if any of the conditions are present.</p>
  
  <p><strong>What would be the proper way use any() in this case? Or better yet, what needs to be done for this method to work?</strong></p>
  
  <p>Assume that the Selenium .get('url') has already been executed immediately prior to calling this method.</p>
  
  <pre><code>def wait_with_xpath_expectation(self, search_elements, timeout=6, max_attempts=3):
      """
      Selenium wait for an element(s) designated by Xpath to become available in the DOM. Useful for javascript AJAXy
      loading pages where content may be be rendered dynamically on the client side after page load appears complete.
      search_elements may be one Xpath as a string or many as a list. This allows for any of multiple elements on a
      page or pages to be determined to have loaded based on expectations.
      :param search_elements: string or list (strings converted to lists), Xpath(s)
      :param timeout: int, seconds
      :param max_attempts: int, time to wait before giving up on page loading
      :return: Boolean, True if page has loaded, False if all attempts have failed
      """
  
      # Page is not loaded yet
      loaded = False
  
      # Initialize attempt count
      attempt = 0
  
      # If only one element has been passed, ensure it is encapsulated by a list
      if type(search_elements) is str:
          search_elements = [search_elements]
  
      # Begin the polling loop
      while attempt &lt; max_attempts:
  
          try:
  
              while loaded is False:
                  # Create a list of expected elements using list comprehension
                  expectations = [EC.presence_of_element_located((By.XPATH, element)) for element in search_elements]
  
                  # Define wait
                  wait = WebDriverWait(self.browser, timeout)
  
                  # Execute
                  wait.until(any(expectations))
  
                  # Acknowledge load
                  loaded = True
  
                  print("Success: Page loaded based on expectations")
  
                  # Exit returning True for load
                  return loaded
  
          except TimeoutException as e:
  
              # Increment attempts
              attempt += 1
  
              # Check again if max attempts has not been exceeded
              while attempt &lt; max_attempts:
  
                  # Increase timeout by 20%
                  timeout *= .2
  
                  # Try again 
                  continue
  
              # Print an error if max attempts is exceeded
              print("Error: Max load with expectations attempts exceeded,", e)
  
              # Exit returning False for load
              return loaded
  </code></pre>