Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

474
Vistas
Difference between using @FindBy and By; what could be thre reason for this error?

I am automating https://www.zoho.com/login.html. This page has sign in section inside a frame. When i switch through different frames and search for my Email/Phone field (Sign In section), i can find it and then hence use the working block (below) but cannot use the similar code (also below) the only difference between two block is how i have identified my userNameInputBox element.

//This is working

       List<WebElement> iframeElements =   driver.findElements(By.tagName("iframe"));
                int nFrames = iframeElements.size();

        //Switching frame to go to login frame  
        for (int i=0; i<=nFrames ; i++) {
            System.out.println("nFrames: " +nFrames);
            driver.switchTo().frame(i);
            if (driver.findElement(By.name("lid")).isDisplayed()){


                driver.findElement(By.name("lid")).sendKeys("myuserName1");
}}

However if i use this (below code) it does not work and instead gives me NullPointerException in the line where i .click my userNameInput into username field.

///This is not working

//Elements

    @FindBy(name="lid")
    WebElement userNameInput;

//Switching frame to go to login frame  
        for (int i=0; i<=nFrames ; i++) {
            System.out.println("nFrames: " +nFrames);
            driver.switchTo().frame(i);
            if (driver.findElement(By.name("lid")).isDisplayed()){
                userNameInput.click(); //clicking the inputBox
                userNameInput.sendKeys("myuserName"); //Sendingkeys into
}}

Can somebody please explain what could be the reason of such anomaly? Or point out what have i missed? I want to use @FindBy for the WebElement.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

The @FindBy tag is designed to work with the Page Object model. To use it, you have to initialize the page object with the PageFactory so that the fields are initialized and then "found" by the webdriver.

See https://github.com/SeleniumHQ/selenium/wiki/PageFactory for the documentation on it.

So before you try to use the userNameInput field, you'll have to have some sort of line like

PageFactory.initElements(driver, page); (where the page var is a class using the @FindBy annotation.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda