Индуцировать WebDriverWait
() и ждать element_to_be_clickable
() и следующих xpath
.
WebDriverWait(browse,15).until(EC.element_to_be_clickable((By.XPATH,"//button[@class='qc-cmp-button' and contains(.,'I accept')]"))).click()
Добавить следующие библиотеки.
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
Код :
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
url='https://www.whoscored.com/Search/?t=Crystal+Palace'
browse=webdriver.Chrome()
browse.get(url)
WebDriverWait(browse,15).until(EC.element_to_be_clickable((By.XPATH,"//button[@class='qc-cmp-button' and contains(.,'I accept')]"))).click()
Обозреватель sanpshot:
Обновление :
cookie=btn=WebDriverWait(browse,15).until(EC.presence_of_element_located((By.XPATH,"//button[@class='qc-cmp-button' and contains(.,'I accept')]")))
browse.execute_script("arguments[0].click();", cookie)