Selenium webdriver 在硒中找不到元素

Selenium webdriver 在硒中找不到元素,selenium-webdriver,Selenium Webdriver,我的代码找不到元素。请任何人帮助我走出我的错误 测试用例 @Test public void main() throws Exception { Thread.sleep(5000); System.out.println("Before sign in action execution"); SignIn_Action.Execute(iTestCaseRow); } 签署行动 public class SignIn_Action{ p

我的代码找不到元素。请任何人帮助我走出我的错误

测试用例

    @Test 
public void main() throws Exception {
    Thread.sleep(5000);
    System.out.println("Before sign in action execution");
    SignIn_Action.Execute(iTestCaseRow);
}
签署行动

    public class SignIn_Action{
       public static void Execute(int iTestCaseRow) throws Exception{
           // Fetch user name from Excel
           String sUserName = ExcelUtils.getCellData(iTestCaseRow, Constant.col_UserName);
           System.out.println("User Name read from --> "+ sUserName);
           // Fetch password from Excel
           String sPassword = ExcelUtils.getCellData(iTestCaseRow, Constant.col_Password);
           System.out.println("Password read from excel --> "+ sPassword);
           LoginPageObjects.txtbx_username().sendKeys(sUserName);
           LoginPageObjects.txtbx_password().sendKeys(sPassword);
           LoginPageObjects.btn_login().click();
   }
登录地理对象类

    public class LoginPageObjects extends BaseClass {
    private static WebElement element = null; 
    public LoginPageObjects(WebDriver driver){
        super(driver);
    }

     public static WebElement txtbx_username(){  
        try {       
        WebElement element = null;          
        System.out.println("Inside txtbx_username method");      
        element = driver.findElement(By.name("first_name"));        
        System.out.println("Fetched element name is : "+element);    
        Log.info("Username text box found");
        }catch (Exception e){        
            Log.error("UserName text box is not found on the Login Page");
            throw(e);
            } 
        return element;
        }
}
}
    public class BaseClass {
    public static WebDriver driver;
    public static boolean bResult;
    public  BaseClass(WebDriver driver){
        BaseClass.driver = driver;
        BaseClass.bResult = true;
    }
}
基类

    public class LoginPageObjects extends BaseClass {
    private static WebElement element = null; 
    public LoginPageObjects(WebDriver driver){
        super(driver);
    }

     public static WebElement txtbx_username(){  
        try {       
        WebElement element = null;          
        System.out.println("Inside txtbx_username method");      
        element = driver.findElement(By.name("first_name"));        
        System.out.println("Fetched element name is : "+element);    
        Log.info("Username text box found");
        }catch (Exception e){        
            Log.error("UserName text box is not found on the Login Page");
            throw(e);
            } 
        return element;
        }
}
}
    public class BaseClass {
    public static WebDriver driver;
    public static boolean bResult;
    public  BaseClass(WebDriver driver){
        BaseClass.driver = driver;
        BaseClass.bResult = true;
    }
}
我的问题在下面的代码中

element = driver.findElement(By.name("first_name"));
此代码不是find元素,它显示以下错误消息

java.lang.NullPointerException
at pageObjects.LoginPageObjects.txtbx_username(LoginPageObjects.java:27)

添加相关的html.IMO,这是由于
元素的声明冲突造成的。一旦声明
private static WebElement=null
next再次
WebElement=null