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

218
Vistas
JavaScript Error Element is null: while interacting ShadownDom element

I am writing code in Javascript to automate the website https://www.fashionette.co.uk/. I have to use cookies when the user lands on the page for the first time

I am writing the following code to get cookies:

JavascriptExecutor js = (JavascriptExecutor)webdriver;
WebElement element= (WebElement) js.executeScript("return document.getElementById('usercentrics-root').shadowRoot.querySelector(\"[data-testid='uc-accept-all-button']\");");
            element.click()

it locate element in browser correctly:

enter image description here

But In Intellij it gives me error:

java.lang.NullPointerException: Cannot invoke "org.openqa.selenium.WebElement.click()" because "element" is null

enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

If you are using Java create a browser instance and find elements:

System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");           
WebDriver driver = new ChromeDriver(); 
driver.get("http://www.google.com/");   
WebElement WE = driver.findElementByCss("YourCSSSelector"); 
WE.click();

If you are using JavaScript change your into:

WebElement element = (WebElement) js.executeScript
("document.getElementById('usercentrics-root').
shadowRoot.querySelector(\"[data-testid='uc-accept-all-button'])\");
about 4 years ago · Juan Pablo Isaza 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