How to clear chrome browsing data using selenium?

I want clear the browsing data in the middle of my test to check the session data and login again after clearing that. I am using driver.manage().deleteAllCookies but its not working correctly that’s why I wanted to clear it from the settings.

Hi Aaron,

You can use the following code to clear the browsing data on the Chrome browser. This works locally as well as on LambdaTest Grid.

JavascriptExecutor js = (JavascriptExecutor)driver;
WebElement ele = (WebElement) js.executeScript("return document.querySelector(\"body > settings-ui\").shadowRoot.querySelector(\"#main\").shadowRoot.querySelector(\"settings-basic-page\").shadowRoot.querySelector(\"#basicPage > settings-section:nth-child(8) > settings-privacy-page\").shadowRoot.querySelector(\"settings-clear-browsing-data-dialog\").shadowRoot.querySelector(\"* /deep/ #clearBrowsingDataConfirm\")");
js.executeScript("arguments[0].click();", ele);

Hope this helps!