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:
JavaScript
x
14
14
1
options = Options()
2
options.headless = False
3
driver = webdriver.Firefox(options=options, executable_path=r'geckodriver.exe')
4
driver.get(url)
5
# ("Headless Firefox Initialized")
6
#dins del id= cookie-banner
7
frame = driver.find_element(by=By.CSS_SELECTOR,value = '[id = "cookie-banner"]')
8
print(frame)
9
buttons = frame.find_elements(by=By.TAG_NAME, value='button')
10
print(buttons)
11
buttons[0].click()
12
13
time.sleep(5)
14
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
JavaScript
1
2
1
driver.find_element(By.CSS_SELECTOR, '#close').click()
2
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
JavaScript
1
5
1
overlay = driver.find_element(By.CSS_SELECTOR, 'div.cookies-overlay')
2
driver.execute_script("arguments[0].style.display = 'none';", overlay)
3
banner = driver.find_element(By.CSS_SELECTOR, '#cookie-banner')
4
driver.execute_script("arguments[0].style.display = 'none';", banner)
5