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

271
Vistas
Javascript works well on the browser console but not in Selenium JavascriptExecutor

I'm trying to click on some pseudo elements using Selenium Java. According to some researches I know that Selenium doesn't support direct clicks on those elements, so I have to use JavascriptExecutor for that purpose.

Problem is it works well when I tried on the browser console, but not in my Selenium Java program. Below is what I'm trying to do.

I want to click on the highlighted arrow element

End then I want to click on the last element (test)

Here is what happens when I use JavascriptExecutor in Selenium.

The list of elements is displayed in the wrong location

I got the error : javascript error: Cannot read properties of null (reading 'click') when trying to click on the element test

Below is the code I'm using in Selenium:

public void JSclick2(String cssPath, String pseudo, String description)
        throws InterruptedException, IOException, UnsupportedAudioFileException, LineUnavailableException {
    // Perform click action on the element

try {
    JavascriptExecutor js = (JavascriptExecutor) driver;
    String JScommand = "document.querySelector('"+ cssPath + "', '" + pseudo + "').click()";
    System.out.println(JScommand);
    js.executeScript(JScommand);
} catch (Exception e) {
    e.printStackTrace();
    System.out.println(e.getMessage());
    printMessage(description);
}

}

Pls tell me why the problem happens and how to fix it. Thanks very much!

about 4 years ago · Juan Pablo Isaza
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