title: How can I check if an element exists on a page using Selenium XPath?
body: <p>I'm writing a script in to do some webscraping on my Firebase for a few select users. After accessing the events page for a user, I want to check for the condition that no events have been logged by that user first. </p>
  
  <p>For this, I am using Selenium and Python. Using XPath seems to work fine for locating links and navigation in all other parts of the script, except for accessing elements in a table. At first, I though I might have been using the wrong Xpath, so I copied the path directly from Chrome's inspection window - still no luck.</p>
  
  <p>As an alternative, I have tried to copy the page source and pass it into beautiful soup, then parse it there to check for the element. No luck there either.</p>
  
  <p>Here's some of the code, and some of the HTML I'm trying to parse. Where am I going wrong? </p>
  
  <pre><code># USING WEBDRIVER - ALWAYS TRIGGERS EXCEPTION 
  def check_if_user_has_any_data():
  try:
      time.sleep(10)
      element = WebDriverWait(driver, 10).until(EC.presence_of_all_elements_located((By.XPATH, '//*[@id="event-table"]/div/div/div[2]/mobile-table/md-whiteframe/div[1]/ga-no-data-table/div')))
      print(type(element))
      if element == True:
          print("found empty state by copying xpath directly - bit risky, but it seems to have worked")
      else:
          print("did'nt find empty state")
  except:
      print("could not find the empty state element", EC)
  
  
  # USING BEAUTIFULSOUP
  def check_if_user_has_any_data#2():
      time.sleep(10)
      html = driver.execute_script("return document.documentElement.outerHTML")
      soup = BeautifulSoup(html, 'html.parser')
      print(soup.text[:500])
      print(len(soup.findAll('div', {"class": "table-row-no-data ng-scope"})))
  
  
  # HTML 
  &lt;div class="table-row-no-data ng-scope" ng-if="::config" ng-class="{overlay: config.isBuilderOpen()}"&gt;
    &lt;div class="no-data-content layout-align-center-center layout-row" layout="row" layout-align="center center"&gt;
      ...
  &lt;/div&gt;
  </code></pre>
  
  <p>The first version triggers the exception. Expected to evaluate 'element' as True. Actual, element is not found.</p>
  
  <p>The second version prints the first 500 characters (correctly, as far as I can tell), but returns '0'. Expected to return '1' after inspecting page source.</p>