Home > front end >  How to close privacy pop ups with selenium that rewrites the html
How to close privacy pop ups with selenium that rewrites the html

Time:05-04

I am working on python and i am trying to close the privacy pop up in this page: https://www.fotocasa.es/es/comprar/vivienda/-barcelona-capital/163381243/d?RowGrid=2&tti=1&opi=300

As i understand selenium acts like a normal "chrome" so it should works as I see when inspected. Searching for similar questions states that you need to be in the same frame as the pop up, but in this case I understand taht the script rewrites the html so it should work searching the element (as i see it when inspecting the webpage):

try:
        element = WebDriverWait(driver, 50).until(
            EC.presence_of_element_located((By.CLASS_NAME, "sui-AtomButton sui-AtomButton--primary sui-AtomButton--solid sui-AtomButton--center "))
        )
        element.click()
        print('\n\nPRESSED\n\n')
finally:
        driver.quit()

This does not work, what way should i use in order to get rid of the pop up?

CodePudding user response:

It's working.You have to select accept button correctly which is [data-testid="TcfAccept"]

import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options


option = webdriver.ChromeOptions()
option.add_argument("start-maximized")

#chrome to stay open
option.add_experimental_option("detach", True)

driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()),options=option)
driver.get('https://www.fotocasa.es/es/comprar/vivienda/-barcelona-capital/163381243/d?RowGrid=2&tti=1&opi=300')
time.sleep(2)

driver.find_element(By.CSS_SELECTOR,'[data-testid="TcfAccept"]').click()          
 
  • Related