Getting Passed Privacy Notices and Cookie Policies (Java)

Getting Passed Privacy Notices and Cookie Policies (Java)

Sometime your tests will be interrupted by a dialog appearing on the page (usually a privacy policy or something similar), as the test uses a fresh browser each time. In most cases the solution is to just wait until the accept button is clickable using ExpectedConditions and then clicking on said element.

WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.elementToBeClickable(By.id("accept-choices"))).click();

If you planning on writing multiple tests for this webpage, add the code required at the start of each test method.

In order to do this you need to add the following lines to your imports:

import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

See Working Example



Using Python

Leave a reply

Your email address will not be published. Required fields are marked*

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.