这是主类:创建了 2 个类,一个是主类,另一个是“TotpGenerator”类。在其他类中编写并在主类中调用的令牌代码。
我可以在登录令牌文本字段出现后登录网站,他们的令牌不是从基于此代码的“密钥”中获取的。任何人都可以帮助我。
问题是:未使用密钥获取身份验证器令牌:
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());
}
}
在像这样创建的另一个类中:并在主类中“调用”,出现以下错误。
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;
}
}
得到错误:
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)