Getting Passed Privacy Notices and Cookie Policies (Python)

Getting Passed Privacy Notices and Cookie Policies (Python)

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 expected_conditions and then clicking on said element.

wait = WebDriverWait(self.driver, 10)
wait.until(expected_conditions.element_to_be_clickable((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:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions

See Working Example



Using Java

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.