NullPointer Exception is displayed when static webelement is used with @FindBy
Using driver.findElement.By.id("usr"),
我能够找到元素和sendkeys 但是usernameTB.sendKeys(username)抛出了空指针异常
public class LoginPage extends TestBase {
// Page Factory or Object Repository
@FindBy(id = "usr")
static WebElement usernameTB;
public LoginPage() {
PageFactory.initElements(driver, this);
}
public static void loginFunction(String env, String username, String password) {
try
{
if (env != null && username!=null && password!=null) {
if (env.equals("dev")) {
driver.findElement(By.id("usr")).sendKeys(username);
usernameTB.sendKeys(username);}} catch(Exception e)
{
e.printstacktrace();
}}