Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

272
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda