21.7 C
New York
Thursday, November 7, 2024

automated testing – The right way to resolve Null error displayed for shadowRoot ingredient?


I’ve written this code during which I’m able to get the shadow ingredient:

bundle org.instance; 
import org.openqa.selenium.JavascriptExecutor; 
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement; 
import org.openqa.selenium.chrome.ChromeDriver; 
public class Essential { public static void foremost(String[] args) 
{System.out.println("Good day and welcome!"); 
System.setProperty("webdriver.chrome.driver", "chromedriver.exe"); 
WebDriver driver= new ChromeDriver(); 
driver.get("https://store.mercedes-benz.com/en-au/store/car/srp/demo"); 
JavascriptExecutor jse = (JavascriptExecutor) driver; 
WebElement agreeBtn= (WebElement) jse.executeScript("return doc.querySelector('cmm-cookie-banner')    .shadowRoot.querySelector('div').querySelector('div').querySelector('cmm-buttons-wrapper').querySelector('wb7-button:nth-of-type(2) ').shadowRoot.querySelector('button.button')");
((JavascriptExecutor)driver).executeScript("arguments[0].click on();", agreeBtn); } }

The under is the output once I run this program:

Nov 05, 2024 10:03:15 PM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch 
WARNING: Unable to search out an actual match for CDP model 130, returning the closest model; discovered: 129; Please replace to a Selenium model that helps CDP model 130 Exception in thread "foremost" 
org.openqa.selenium.JavascriptException: javascript error: Can not learn properties of null (studying 'shadowRoot') (Session data: chrome=130.0.6723.92) 
Construct data: model: '4.25.0', revision: '030fcf7918' 
System data: os.identify: 'Home windows 11', os.arch: 'amd64', os.model: '10.0', java.model: '17.0.8' 
Driver data: org.openqa.selenium.chrome.ChromeDriver 
Command: [647d6b65e33549f28a4ea4e137e0a4f5, executeScript {script=return document.querySelector('cmm-cookie-banner').shadowRoot.querySelector('div').querySelector('div').querySelector('cmm-buttons-wrapper').querySelector('wb7-button:nth-of-type(2) ').shadowRoot.querySelector('button.button'), args=[]}] Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 130.0.6723.92, chrome: {chromedriverVersion: 129.0.6668.9 (ab04602ab643c..., userDataDir: 
C:UsersusAppDataLocalT...}, fedcm:accounts: true, goog:chromeOptions: {debuggerAddress: localhost:54013}, networkConnectionEnabled: false, pageLoadStrategy: regular, platformName: home windows, proxy: Proxy(), se:cdp: ws://localhost:54013/devtoo..., se:cdpVersion: 130.0.6723.92, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:extension:minPinLength: true, webauthn:extension:prf: true, webauthn:virtualAuthenticators: true} 
Session ID: 647d6b65e33549f28a4ea4e137e0a4f5 at java.base/jdk.inside.mirror.NativeConstructorAccessorImpl.newInstance0(Native Methodology) at java.base/jdk.inside.mirror.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77) at java.base/jdk.inside.mirror.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.base/java.lang.mirror.Constructor.newInstanceWithCaller(Constructor.java:499) 
at java.base/java.lang.mirror.Constructor.newInstance(Constructor.java:480) 
at org.openqa.selenium.distant.ErrorCodec.decode(ErrorCodec.java:167) at org.openqa.selenium.distant.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:138) at org.openqa.selenium.distant.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:50) at org.openqa.selenium.distant.HttpCommandExecutor.execute(HttpCommandExecutor.java:190) at org.openqa.selenium.distant.service.DriverCommandExecutor.invokeExecute(DriverCommandExecutor.java:216) at org.openqa.selenium.distant.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:174) at org.openqa.selenium.distant.RemoteWebDriver.execute(RemoteWebDriver.java:545) at org.openqa.selenium.distant.RemoteWebDriver.executeScript(RemoteWebDriver.java:476) at org.instance.Essential.foremost(Essential.java:20) 
Course of completed with exit code 1.

Additionally, once I verify for the DOM ingredient into browser, I’m able to find it.

Are you able to please advise how can I resolve this? I’m actually in want to resolve this. I can be obliged of your assist. Thanks

enter image description here
enter image description here
enter image description here

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles