Gmail 2 factor authentication using selenium webdriver in java

import java.util.concurrent.TimeUnit;

import org.jboss.aerogear.security.otp.Totp;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class Gmail2FA {

    public static void main(String[] args) {
       
        System.setProperty("webdriver.gecko.driver","D:\\QA\\geckodriver-v0.24.0-win64\\geckodriver.exe");
        WebDriver driver = new FirefoxDriver();
        String baseUrl = "https://gmail.com";
       
        driver.get(baseUrl);
       
            
        driver.manage().window().maximize();
 

        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
       

      WebElement email_phone =          driver.findElement(By.xpath("//input[@id='identifierId']"));
        email_phone.sendKeys("<<YOUR ACCOUNT>>@gmail.com");
        driver.findElement(By.id("identifierNext")).click();
        

   WebElement password = driver.findElement(By.xpath("//input[@name='password']"));
        WebDriverWait wait = new WebDriverWait(driver, 20);
        wait.until(ExpectedConditions.elementToBeClickable(password));
        password.sendKeys("<<YOUR PASSWORD>>");
        driver.findElement(By.id("passwordNext")).click();
       
       
        String otpKeyStr;

        String twoFactorCode;
       
        otpKeyStr = "4wer 43r5 bsz5g liec vr5s dgtw"; // <- this 2FA secret key.

        Totp totp = new Totp(otpKeyStr);

        twoFactorCode = totp.now();

       // logger.info(twoFactorCode);

              WebElement enter2FA = driver.findElement(By.xpath("//input[@id='totpPin']"));
      
       enter2FA.sendKeys(twoFactorCode);
       wait.until(ExpectedConditions.elementToBeClickable(enter2FA));
       driver.findElement(By.className("CwaK9")).click();


        //logger.info("Clicking on the submit button");
//RveJvd snByac
        //clickBtn.click();

        //sleep(2);

    }

}