1

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

Joksova
  • 61
  • 8

4 Answers4

0

Try using this

driver.find_element_by_class_name('css-47sehv').click()

on place of

driver.find_element(By.CLASS_NAME," css-47sehv").click()

joanis
  • 10,635
  • 14
  • 30
  • 40
tntzx
  • 31
  • 5
0

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.

0

Though the element AGREE contains the classname css-47sehv, the value looks dynamic and may change in a short interval or once the application gets restarted.


Solution

To click on the element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following locator strategies:

  • Using CSS_SELECTOR:

    driver.get("https://www.soccerstats.com/matches.asp?matchday=1#")
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button[mode='primary']"))).click()
    
  • Using XPATH:

    driver.get("https://www.soccerstats.com/matches.asp?matchday=1#")
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@mode='primary' and text()='AGREE']"))).click()
    
  • Note: You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
-1

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()
KunduK
  • 32,888
  • 5
  • 17
  • 41