Currently, I am developing an automation script in Javascript for the website . The main objective is to implement cookies when a user visits the site for the first time.
Below is an excerpt of the code that I have written to retrieve 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()
The code successfully identifies the element in the browser:
https://i.sstatic.net/cFyRG.jpg
However, when executing the script in Intellij, I encounter the following error:
java.lang.NullPointerException: Cannot invoke "org.openqa.selenium.WebElement.click()" because "element" is null