title: Learning to use Assert and Asserttrue in Python for selenium web driver
body: <p>Im trying to make a python webdriver to load a webpage and then assert true and run a print command if a text or object is there, and if not I want it to just continue running my loop. Im a noob to python and have been learning from Learn python the Hard Way, and reading documentation. Ive spent the last day or so trying to get my code finding text or elements, but it doesnt feed back info...Here is my code so far minus the top part about going to the webpage, I am just stuff on this count loop assert logic.</p>
  
  <pre><code>count = 1000.00
  while count &lt; 1000.03:
      driver.find_element_by_id("select").clear()
      driver.find_element_by_id("select").send_keys(str(count))
      time.sleep(1)
      driver.find_element_by_id("BP").click()
      driver.find_element_by_id("BP").click()
      count += 0.01 ## increases count to test
      highervalue = driver.find_element_by_link_text("Select Error")
      assertTrue(driver.link_contains_match_for("")) ##could also be, ##text_containt_match_for("ex") or driver.assertTrue(element in WEBPAGE)??
          print 'Someone is %.7r' %count
      else:
          print 'I have %.7r' %count
      time.sleep(1)
  </code></pre>
  
  <p>then the loop starts over again. The issue i am having is I want to find "Select Error" on the webpage in some kind of form, link, or text, and then if it is there print me a msg, and if not, to just continue my loop.</p>
  
  <p>Is it better to use assert/asserttrue, or something like </p>
  
  <pre><code>def is_element_present(self, how, what):
      try: self.driver.find_element(by=how, value=what)
      except NoSuchElementException, e: return False
      return True
  </code></pre>
  
  <p>or </p>
  
  <p>Some other examples I have searched about that could be used:</p>
  
  <pre><code>self.assertTrue(self.is_element_present(By.ID, "FOO"))
  
  self.assertTrue(self.is_element_present(By.TEXT, "BAR"))
  
  self.assertTrue(self.is_text_present("FOO"))
  
  self.assertTrue(self.driver.is_text_present("FOO"))
  </code></pre>
  
  <p>Can someone let me know how I would write the part when I find something in the webpage and it gives me feedback if found?</p>