How to assert/verify successful login using Python / Selenium Webdriver
<p>I have done a little research and could not find any answer specific to Selenium WebDriver with Python. 
I can successfully sign into the page but I cannot find way(s) to verify that the login was successful. Page title does not work for me since it does not change. 
Python Selenium documentation does not have any good explanation or examples. 
All I want to do after this code is to put a line and assert that the username "Tuto" is visible on the page</p>

<pre><code>LoginButtonLocator = "//a[contains(text(), 'Login')]"
facebookConnectButtonLocator = "//a[contains(text(), 'Connect with Facebook')]"

facebookLoginLocatorID = "email"
facebookPasswordLocatorID = "pass"
facebookLoginButtonLocatorID = "loginbutton"

LoginButtonElement = WebDriverWait(driver, 20).until(lambda driver: driver.find_element_by_xpath(LoginButtonLocator))
LoginButtonElement.click()
facebookConnectButtonElement = WebDriverWait(driver, 20).until(lambda driver: driver.find_element_by_xpath(facebookConnectButtonLocator))
facebookConnectButtonElement.click()
facebookLoginElement = WebDriverWait(driver, 20).until(lambda driver: driver.find_element_by_id(facebookLoginLocatorID))
facebookLoginElement.send_keys(facebookID)
facebookPasswordElement = WebDriverWait(driver, 20).until(lambda driver: driver.find_element_by_id(facebookPasswordLocatorID))
facebookPasswordElement.send_keys(facebookPW)
facebookLoginButtonElement = WebDriverWait(driver, 20).until(lambda driver: driver.find_element_by_id(facebookLoginButtonLocatorID))
facebookLoginButtonElement.click()
</code></pre>

<p>I am working with the Javascript API instead of the Python version, so the syntax is different, but here is how I would get about it (using mocha as a test framework):</p>

<pre><code>facebookLoginButtonElement.click().then(function(_) {
    driver.findElement(By.xpath('//a[text() = "Tuto"]')).then(function(userLink) {
        assert.ok(userLink);
    });
});
</code></pre>

<p>In the javascript version, if <code>&lt;a ...&gt;Tuto&lt;/a&gt;</code> can't be found there would be an error before the callback is called, so the assertion would be redundant (would only get there if the link was found), but I find it as self-documenting so I add the assert.</p>

python selenium selenium-webdriver