Solution 1 :

It is inside an iframe, try the below code, its working:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it(driver.find_element(By.CSS_SELECTOR, "iframe#sp_message_iframe_575848")))

driver.find_element(By.XPATH,".//*[@title='ACCEPTEER ALLE']").click()

Solution 2 :

After checking you inquiry , you can achieve that by doing like so:

 from selenium.webdriver.common.action_chains import ActionChains

 action = ActionChains(driver)
 cookie_page = driver.find_element_by_id('cookie_page_id') 
 action.move_to_element(cookie_page).perform()`

=> Now your inside the cookie page,to find your accept cookies path.

Problem :

I’m trying to gather some information from transfermarkt with a scraper, but when I open the page with a bot I always get a huge prompt to accept cookies. I’ve tried finding the element for the accept button by copying the full xpath, copying the relative xpath, and using ‘//button[@title=”ACCEPTEER ALLE”]’, but it can never find the element. I’ve also tried using the wait until method, but that always led to time out errors because it still couldn’t find it, and the page loads quickly. Does anyone know what’s wrong?

This is the button:

<button title="ACCEPTEER ALLE" class="message-component message-button no-children focusable sp_choice_type_11 last-focusable-el" style="padding: 10px 15px; margin: 5px 10px; border-width: 2px; border-color: rgb(92, 166, 255); border-radius: 4px; border-style: solid; font-size: 14px; font-weight: 400; color: rgb(255, 255, 255); font-family: verdana, geneva, sans-serif; width: 225px; background: rgb(0, 25, 63);">ACCEPTEER ALLE</button>

This is my code:

league = "Primera DivisiĆ³n"
url = "https://www.transfermarkt.nl/schnellsuche/ergebnis/schnellsuche?query={}".format(league)
browser = webdriver.Chrome()
browser.get(url)
sleep(10)
    
button = browser.find_element(By.XPATH, '//button[@title="ACCEPTEER ALLE"]')
button.click()

Comments

Comment posted by Fazlul

At first, you have to show us what’s the value of the variable league?

Comment posted by Archiee

@MKJ noticed you haven’t accepted any answer, soo would vote for any answer helped you below so this post will marked as closed for future use.

By