There is a cookie on this page which i have tried to close using selenium java and testNG but not closing. The url is https://hausrat.allianz.de/
Below is my code:
public void closeCookieNotification() {//*[@id="onetrust-accept-btn-handler"]
try {
// Check if the cookie notification element is present
WebElement cookieNotification = driver.findElement(By.xpath("//*[@id=\"onetrust-accept-btn-handler\"]"));
// Close the cookie notification if present
if (cookieNotification.isDisplayed()) {
WebElement closeButton = driver.findElement(By.xpath("//*[@id=\"onetrust-accept-btn-handler\"]"));
closeButton.click();
}
} catch (Exception e) {
// Cookie notification not present or error occurred while closing, ignore
System.out.println(e.getMessage());
}
}