title: Checking if element exists with Python Selenium
body: <p>I have a problem - I am using the selenium (firefox) web driver to open a webpage, click a few links etc. then capture a screenshot.</p>
  
  <p>My script runs fine from the CLI, but when run via a cronjob it is not getting past the first find_element() test. I need to add some debug, or something to help me figure out why it is failing.</p>
  
  <p>Basically, I have to click a 'log in' anchor before going to the login page. The construct of the element is:</p>
  
  <pre><code>&lt;a class="lnk" rel="nofollow" href="/login.jsp?destination=/secure/Dash.jspa"&gt;log in&lt;/a&gt;
  </code></pre>
  
  <p>I am using the find_element By LINK_TEXT method:</p>
  
  <pre><code>login = driver.find_element(By.LINK_TEXT, "log in").click()
  </code></pre>
  
  <p>I am a bit of a Python Noob, so I am battling with the language a bit...</p>
  
  <p>A) How do I check that the link is actually being picked up by python? Should I use try/catch block?</p>
  
  <p>B) Is there a better/more reliable way to locate the DOM element than by LINK_TEXT? E.g. In JQuery, you can use a more specific selector $('a.lnk:contains(log in)').do_something();</p>
  
  <hr>
  
  <p>I have solved the main problem and it was just finger trouble - I was calling the script with incorrect parameters - Simple mistake.</p>
  
  <p>I'd still like some pointers on how to check whether an element exists. Also, an example/explanation of implicit / explicit Waits instead of using a crappy time.sleep() call. </p>
  
  <p>Cheers, ns</p>