Selenium 单击按钮元素在错误点不可单击

问题描述 投票:0回答:1

CoinPoker 排行榜页面

我想单击昨天按钮复制昨天的数据,但这样做时收到错误
我的目标是能够单击“昨天”按钮并在单击按钮后解析位于下面的数据。

错误

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)

代码

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()
python selenium-webdriver selenium-chromedriver
1个回答
0
投票

您可以尝试通过文字获取按钮

Yesterday

...
try:
    button = driver.find_element(By.XPATH, "//button[normalize-space()='Yesterday']")
    button.click()
    print("Button clicked!")
except Exception as e:
    print(f"Error: {e}")
...
© www.soinside.com 2019 - 2024. All rights reserved.