0

I'm using selenium and I have a problem handling the accept cookies pop-up.

from selenium import webdriver
from selenium.webdriver.support.ui import Select
import time

web = webdriver.Chrome("C:/chromedriver")
web.get('https://www.spaargids.be/sparen/schuldsaldo-berekenen.html')

time.sleep(2)

akkoord = web.find_element_by_xpath('/html/body/div/div[2]/div[3]/button[1]')

When I inspect the element, I can easily find it. But selenium is unable to do it. Does anybody know how to fix this?

wokter
  • 226
  • 3
  • 14
  • Possible duplicate? https://stackoverflow.com/questions/64032271/handling-accept-cookies-popup-with-selenium-in-python – Buddy Bob Apr 07 '21 at 15:12

1 Answers1

1

The problem is that the element is inside an iframe, you need to switch to the respective iframe.

Try this before akkoord variable:

web.switch_to.frame(web.find_element_by_xpath('//iframe[@title="SP Consent Message"]'))

That should make it work, then use the same approach but updating the XPATH to switch to the iframe where the content is.

rekeson21
  • 189
  • 9