I'm trying to click on "Agree" button on this website https://www.soccerstats.com/matches.asp?matchday=1# but it didn't work for me using this code:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
import time
s=Service("C:/Users/dhias/OneDrive/Bureau/stgg/chromedriver.exe")
driver=webdriver.Chrome(service=s)
driver.get("https://www.soccerstats.com/matches.asp?matchday=1#")
driver.maximize_window()
time.sleep(1)
driver.find_element(By.CLASS_NAME," css-47sehv").click()
the css-47sehv
is the class name of the button and here is a picture of the button The blue button
CodePudding user response:
Try using this
driver.find_element_by_class_name('css-47sehv).click()
on place of
driver.find_element(By.CLASS_NAME," css-47sehv").click()
CodePudding user response:
To click on AGREE
button use the following xpath
to identify the element and click.
//button[text()='AGREE']
Code:
driver.find_element(By.XPATH,"//button[text()='AGREE']").click()
Or Use following css selector.
driver.find_element(By.CSS_SELECTOR,"button.css-47sehv").click()
CodePudding user response:
You have to make sure of following:
1-use explicitly Wait to wait the button to/Till appear
try:
element=WebDriverWait(driver,10).until(
EC.presence_of_element_located((By.ID, "AgreeButton"))
)
finally:
driver.quit()
2-Click on the button with correct Xpath:
driver.find_element(By.XPATH,"//button[text()='AGREE']").click()
3-If simple click doesn't work you can use JavaScript and perform methods to click.