mercredi 7 avril 2021

Exception in thread "main" java.lang.IllegalArgumentException: Keys to send should be a not null CharSequence

This is the main class : Created 2 classes, one is main class and other is "TotpGenerator" class. Token code written in other class and calling in main class.

I am able to login the website after login token text field will come, their token is not getting from "Secret key" based on this code. Any one can help me on this.

Issue is: Not getting authenticator token by using secret key:

package Testing;

import java.io.File;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.jboss.aerogear.security.otp.Totp;

public class Testing {

    public static void main(String[] args) throws InterruptedException {
        
        System.setProperty("webdriver.chrome.driver", "C:\\Users\\naga\\eclipse-workspace\\Testing\\drivers\\chromedriver.exe");

        WebDriver driver=new ChromeDriver();
        driver.manage().timeouts().implicitlyWait(5,TimeUnit.SECONDS);
        driver.get("https:aasdsad.com");
        driver.manage().window().maximize();
        driver.findElement(By.xpath("//*[@id=\"center-v-and-h\"]/form/div/input")).sendKeys("abc@gmail.com");
        driver.findElement(By.xpath("//*[@id=\"center-v-and-h\"]/form/div/input")).sendKeys("asasasa");
        driver.findElement(By.xpath("//*[@id=\"center-v-and-h\"]/form/div/div/button")).click();
        driver.findElement(By.name("token")).sendKeys(TOTPGenerator.getTwoFactorCode());
    }
}  
    

In another class created like this :and "calling" in main class, getting below errors.

package Testing;
import java.util.concurrent.TimeUnit;
import org.jboss.aerogear.security.otp.Totp;


public class TOTPGenerator {

    // TODO Auto-generated method stub
    public static String getTwoFactorCode() {
            
        Totp totp = new Totp("qwwqeqweqwZWO5UXSSLUFQUVMVSWOI"); // 2FA secret key
        String twoFactorCode = totp.now(); //Generated 2FA code here
        return twoFactorCode;
                    
    }
}
    
    

Getting errors :

Exception in thread "main" java.lang.IllegalArgumentException: Keys to send should be a not null CharSequence
    at org.openqa.selenium.remote.RemoteWebElement.sendKeys(RemoteWebElement.java:97)

Aucun commentaire:

Enregistrer un commentaire