title: Javascript works well on the browser console but not in Selenium JavascriptExecutor
body: <p>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 <code>JavascriptExecutor</code> for that purpose.</p>
  <p>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.</p>
  <p><a href="https://i.stack.imgur.com/Z2ALZ.png" rel="nofollow noreferrer">I want to click on the highlighted arrow element</a></p>
  <p><a href="https://i.stack.imgur.com/wd53C.png" rel="nofollow noreferrer">End then I want to click on the last element (test)</a></p>
  <p>Here is what happens when I use <code>JavascriptExecutor</code> in Selenium.</p>
  <p><a href="https://i.stack.imgur.com/mEQ1t.png" rel="nofollow noreferrer">The list of elements is displayed in the wrong location</a></p>
  <p>I got the error:</p>
  <blockquote>
  <p>javascript error: Cannot read properties of null (reading 'click')</p>
  </blockquote>
  <p>When trying to click on the element <code>test</code></p>
  <p>Below is the code I'm using in Selenium:</p>
  <pre><code>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 = &quot;document.querySelector('&quot;+ cssPath + &quot;', '&quot; + pseudo + &quot;').click()&quot;;
          System.out.println(JScommand);
          js.executeScript(JScommand);
      } catch (Exception e) {
          e.printStackTrace();
          System.out.println(e.getMessage());
          printMessage(description);
      }
  }
  </code></pre>
  <p>Please tell me why the problem happens and how to fix it.</p>