I am trying to scrap this webpage https://www.tecnocasa.es/venta/piso/barcelona/barcelona/510567.html, the code i use is the following, and i think is correct:
options = Options() options.headless = False driver = webdriver.Firefox(options=options, executable_path=r'geckodriver.exe') driver.get(url) # ("Headless Firefox Initialized") #dins del id= cookie-banner frame = driver.find_element(by=By.CSS_SELECTOR,value = '[id = "cookie-banner"]') print(frame) buttons = frame.find_elements(by=By.TAG_NAME, value='button') print(buttons) buttons[0].click() time.sleep(5)
The buttons are found but when i try to click one i have the error <button class="btn-default"> is not clickable at point (1138,829) because another element <div id="hide-overlay" class="hide-overlay fade-leave-active fade-leave-to"> obscures it
How can i disable this overlay and click the button to accept the conditions of the page?
Advertisement
Answer
Your code works without any problem on my computer, try this one
driver.find_element(By.CSS_SELECTOR, '#close').click()
If also this will not work, you can try this code which hides the banner. However, you should run it each time that a new page is loaded
overlay = driver.find_element(By.CSS_SELECTOR, 'div.cookies-overlay') driver.execute_script("arguments[0].style.display = 'none';", overlay) banner = driver.find_element(By.CSS_SELECTOR, '#cookie-banner') driver.execute_script("arguments[0].style.display = 'none';", banner)