title: Automation login test is failed, but login in web page is successful
body: <p>I am trying to write automation tests for login page. The problem is that my code works as expected (web page is opened and I am logged in) but test is failed. When I trying to debug my code it says that I have problem with clickLoginButton() function but I have no idea what is wrong. Could you please help me? Thanks in advance!</p>
  <p>Here is my class with elements and methods:</p>
  <pre><code>import org.junit.jupiter.params.ParameterizedTest;
  import org.junit.jupiter.params.provider.ArgumentsSource;
  import org.openqa.selenium.By;
  import org.openqa.selenium.Keys;
  import org.openqa.selenium.WebDriver;
  import org.openqa.selenium.WebElement;
  import org.openqa.selenium.support.FindBy;
  import org.openqa.selenium.support.How;
  import org.openqa.selenium.support.PageFactory;
  
  public class LoginData {
  
      private WebDriver driver;
  
      @FindBy(how = How.XPATH, using = &quot;//a[@class = 'close-modal-window']/img&quot;)
      private WebElement close;
  
      @FindBy(how = How.XPATH, using = &quot;//input[@id='email']&quot;)
      private WebElement emailField;
      @FindBy(how = How.XPATH, using = &quot;//input[@id = 'password']&quot;)
      private WebElement passwordField;
      @FindBy(how = How.XPATH, using = &quot;//app-submit-button/button[@class = &quot;//button[@class = 'primary-global-button']&quot;)
      private WebElement loginButton;
  
      @FindBy(how = How.XPATH, using = &quot;//*[@id='header_user-wrp']/li[1]/a&quot;)
      private WebElement userName;
  
  
      public LoginData(WebDriver driver) {
          this.driver = driver;
          PageFactory.initElements(driver, this);
      }
  
      //(&quot;click on 'close' button&quot;)
      public LoginData clickCloseIcon() {
          close.click();
          return this;
      }
  
      //fill in Email
      public LoginData inputEmail(String emailInput) {
          emailField.click();
          emailField.clear();
          emailField.sendKeys(emailInput, Keys.ENTER);
          return this;
      }
  
      //input password | value = {passwordInput}
      public LoginData inputPassword(String passwordInput) {
          passwordField.click();
          passwordField.clear();
          passwordField.sendKeys(passwordInput, Keys.ENTER);
          return this;
      }
  
      // click on login button
      public LoginData clickLoginButton () {
          loginButton.click();
          return new LoginData(driver);
      }
  
      //check if element is displayed when user is logged in 
      public boolean userNameIsDisplayed() {
          return userName.isDisplayed();
      }
  
  
  }
  </code></pre>
  <p>And my login test:</p>
  <pre><code>import io.github.bonigarcia.wdm.WebDriverManager;
  import org.junit.After;
  import org.junit.Assert;
  import org.junit.jupiter.api.AfterEach;
  import org.junit.jupiter.api.BeforeEach;
  import org.junit.jupiter.params.ParameterizedTest;
  import org.junit.jupiter.params.provider.ArgumentsSource;
  import org.openqa.selenium.By;
  import org.openqa.selenium.WebDriver;
  import org.openqa.selenium.chrome.ChromeDriver;
  
  
  
  import java.time.Duration;
  
  import static org.junit.Assert.*;
  
  public class LoginDataTest {
      private WebDriver driver;
  
      final String BASE_URL = &quot;https://ita-social-projects.github.io/GreenCityClient/#/&quot;;
  
      @BeforeEach
      public void beforeMethod() {
          WebDriverManager.chromedriver().setup();
          driver = new ChromeDriver();
          driver.manage().window().maximize();
          driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
          driver.get(BASE_URL);
          driver.findElement(By.partialLinkText(&quot;Увійти&quot;)).click();
  
      }
  
  
      @ParameterizedTest
      @ArgumentsSource(EmailPasswordArgumentsProvider.class)
      public void loginTest(String email, String password) {
          try {
              LoginData login = new LoginData(driver);
              login.inputEmail(email).inputPassword(password).clickLoginButton();
             Assertions.assertTrue(login.userNameIsDisplayed());
          } catch (NullPointerException e) {
              e.printStackTrace();
          }
      }
  
  
      @AfterEach
      public void AfterMethod() {
          driver.quit();
      }
  
  }
  </code></pre>