首页 > 解决方案 > Selenium 按钮不可点击的 Python

问题描述

我正在尝试单击此站点上的下一页按钮。我在 Stack Overflow 上查看了多个针对类似问题提出的解决方案,但它们似乎都不起作用。这是我目前的代码:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

wait = WebDriverWait(driver, 10)
next_button = wait.until(EC.element_to_be_clickable((By.XPATH, "html/body/div/div/div/main/div[3]/div[2]/div/div[3]/div[1]/div[2]/div[2]/div/div[1]/div[3]/button[2]/i/svg")))
driver.execute_script("return arguments[0].scrollIntoView();", next_button)
next_button.click()

任何帮助,将不胜感激。谢谢!

标签: pythonseleniumweb-scrapingselenium-chromedriver

解决方案


您可以尝试如下:

wait = WebDriverWait(driver, 10)
next_button = wait.until(EC.element_to_be_clickable((By.XPATH, '(//*[@class="anticon anticon-right"])[2]')))
driver.execute_script("return arguments[0].scrollIntoView();", next_button)
next_button.click()

推荐阅读