pythonselenium-webdriverselenium-chromedriver

Selenium Clicking Button Element is not clickable at point Error


CoinPoker Leaderboard Page

I want to click yesterday button to copy yesterday's data, but receveing an error doing so
My goal is to be able to click both Yestarday button and parse data located below after clicking button.

Error

DevTools listening on ws://127.0.0.1:50944/devtools/browser/3fb9b8ce-215c-405f-918c-8e232e4f7379
Traceback (most recent call last):
  File "d:\Programowanie_new\coin_poker_lb\main.py", line 17, in <module>
    click_button.click()
  File "C:\Users\pkuzi\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\selenium\webdriver\remote\webelement.py", line 94, in click
    self._execute(Command.CLICK_ELEMENT)
  File "C:\Users\pkuzi\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\selenium\webdriver\remote\webelement.py", line 395, in _execute
    return self._parent.execute(command, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\pkuzi\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\selenium\webdriver\remote\webdriver.py", line 347, in execute
    self.error_handler.check_response(response)
  File "C:\Users\pkuzi\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\selenium\webdriver\remote\errorhandler.py", line 229, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element is not clickable at point (1151, 1563)

Code

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait

driver = webdriver.Chrome()
driver.get("https://coinpoker.com/promotions/daily-cosmic-spins-leaderboard/")

click_button = WebDriverWait(driver, 15).until(
    EC.element_to_be_clickable((By.XPATH, "/html/body/div[2]/div/article/div/section[2]/div/div/div[1]/div/div[2]/div/ul/li[2]/button"))
)

click_button.click()

This also does not work

click_button = driver.find_element(By.XPATH, "//button[text() = 'Yesterday']")

Solution

  • In this case you'll need to emulate the "click" action with JavaScript.

    from selenium import webdriver
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    from selenium.webdriver.common.by import By
    
    url = "https://coinpoker.com/promotions/daily-cosmic-spins-leaderboard/"
    
    options = webdriver.ChromeOptions()
    options.add_argument("--headless=true")
    
    with webdriver.Chrome(options) as driver:
        driver.get(url)
        wait = WebDriverWait(driver, 10)
        selector = By.CSS_SELECTOR, "button.nav-link[aria-selected='false']"
        for button in wait.until(EC.presence_of_all_elements_located(selector)):
            if button.text == "Yesterday":
                driver.execute_script("arguments[0].click();", button)