Q:

Testing logout with selenium

Hi im new to selenium and i have to test if user can logout from page, heres my method for testing it, but unfortunately it doesnt never gets to the page, i think im missing something in the method  :
public boolean logOut() {
    WebDriver driver = getDriver();
    //driver.get(BASE_URL);
    driver.get("http://enos.itcollege.ee/~mkalmo/selenium/menu.php");
    elementById("log_out_link").click();

    if(!driver.getCurrentUrl().equals("http://enos.itcollege.ee/~mkalmo/selenium/index.php"))
    {
        return false;
    }

    return true;
}

Heres the test if user returns to the main page it should return true so the test will pass but it always returns false:
 @Test
public void logOutSuccess() {
    LoginPage loginPage = LoginPage.goTo();
    loginPage.logInWith(USERNAME, CORRECT_PASSWORD);
    System.out.println(driver.getPageSource());
    assertThat(loginPage.logOut(), is(true));
}

A:

Alternatively, you can explicitly wait for the "Log In" button to appear:
WebDriverWait wait = new WebDriverWait(driver, 5);
try {
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.id('log_in_button')));
    return true;
} catch (TimeoutException exception) {
    return false;
}

