title: How do I determine if my Selenium script was able to log in?
body: <p>How can I make this selenium script know if it was able to log in or not? Currently I am using <code>is_displayed()</code> to see if the login form is still on the page. Is there a better way?</p>
  
  <pre><code>driver.find_element_by_id("uname").send_keys("admin")
  driver.find_element_by_id("pwd").send_keys("admin")
  driver.find_element_by_xpath('//*[@id="login_form"]/div/button').click()
  
  # below xpath is code for invalid user id or password message
  if driver.find_element_by_xpath('//*[@id="login_form"]/div[1]').is_displayed():
      output=open("OutputAdmin","w+")
      output.write("Login unsuccessful")
      output.close()
  else:
      output = open("OutputAdmin", "w+")
      output.write("Login successful")
      output.close()
  driver.quit()
  </code></pre>
  
  <p>Now if user id or password is incorrect it is working fine but if they are correct it doesn't execute else code.</p>