0

I am unable to log in to Gmail using my code. Please help

public class first_test {
    WebDriver driver = new ChromeDriver();

    @BeforeTest
    public void tearup()
    {
        WebDriver driver = new ChromeDriver();
        driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
        driver.get("https://accounts.google.com");

    }

  @Test
  public void mail() throws InterruptedException  {
      WebElement email=driver.findElement(By.id("identifierId"));
      email.click();
      email.sendKeys("sharfulumair");
      WebElement password=driver.findElement(By.id("//*[@name=\"password\"]"));
      password.click();
      password.sendKeys("abcd");
  }


  @AfterTest  
  public void teardown()
  {
    driver.close();
  }


}

The error message I got is:

Unable to locate element: {"method":"id","selector":"identifierId"}

PowerStat
  • 3,757
  • 8
  • 32
  • 57
sharful
  • 15
  • 8

1 Answers1

0

Try using wait before accessing the webelement.

public void mail() throws InterruptedException  {
      new WebDriverWait(driver, 60).until(ExpectedConditions.presenceOfElementLocated(By.id("identifierId")));
      WebElement email=driver.findElement(By.id("identifierId"));
      ...............
  }
Sachin
  • 51
  • 1
  • 6