title: Checking if HTML element exists with Python Selenium
body: <p>I am trying to check if an element exists on an HTML page with Selenium/Python.</p>
  
  <p>This is my function:</p>
  
  <pre><code>class runSelenium(object):
  
      def __init__(self):
          # define a class attribute
          self.driver = webdriver.Firefox()
  
      def isElementPresent(self, locator):
          try:
              self.driver.find_element_by_xpath(locator)
          except NoSuchElementException:
              print ('No such thing')
              return False
          return True
  
      def selenium(self):
          self.driver.get("https://somepage.com")
          isElement = self.isElementPresent("//li[@class='item'][6]")
          isElement1 = str(isElement)
  
  
      if __name__ == '__main__':
          run = runSelenium()
          run.selenium()
  </code></pre>
  
  <p>I am trying to pick the result with a Boolean value but with no luck:</p>
  
  <pre><code>isElement = self.isElementPresent("//li[@class='item'][6]")
  </code></pre>
  
  <p>What am I missing here?</p>