I'm, triying to scrape a transfermark web section and I don't want to accept all cookies in popup, but to configure it and accept these changes. I've achieve do click on "option" button in first frame, but when second frame appears I can't click on "save and exit" button. This is my code:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
url = 'https://www.transfermarkt.es/transfers/transfertagedetail/statistik/top/land_id_zu/0/land_id_ab/0/leihe//datum/2022-07-10'
driver = webdriver.Chrome()
driver.minimize_window()
driver.get(url_base)
wait = WebDriverWait(driver, 30)
wait.until(EC.frame_to_be_available_and_switch_to_it((By.XPATH, '//*[@id="sp_message_iframe_575430"]')))
wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="notice"]/div[3]/div[1]/button'))).click()
wait.until(EC.frame_to_be_available_and_switch_to_it((By.XPATH, '//*[@id="sp_message_iframe_225826"]')))
wait.until(EC.element_to_be_clickable((By.XPATH, '/html/body/div/div[2]/div[5]/button[2]'))).click()
thanks
CodePudding user response:
To be able to switch to another iframe you need to switch back to default content first:
...
wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="notice"]/div[3]/div[1]/button'))).click()
driver.switch_to.default_content()
wait.until(EC.frame_to_be_available_and_switch_to_it((By.XPATH, '//*[@id="sp_message_iframe_225826"]')))
...