You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Selenium点击下一页按钮遇ElementNotInteractableException问题求助

解决Selenium点击不可交互div按钮的问题

你的问题核心是目标元素is_displayed()返回False,说明元素当前在页面上不可见,Selenium默认只允许操作可见元素,所以触发了ElementNotInteractableException。以下是几种可行的解决方法:

  • 滚动到元素可见位置
    先将元素滚动到视窗内,再执行点击操作:

    from selenium.webdriver.common.action_chains import ActionChains
    
    next_btn = driver.find_element(By.ID, 'pager_next_page_id')
    ActionChains(driver).move_to_element(next_btn).perform()
    next_btn.click()
    

    或者用JavaScript实现滚动:

    next_btn = driver.find_element(By.ID, 'pager_next_page_id')
    driver.execute_script("arguments[0].scrollIntoView(true);", next_btn)
    next_btn.click()
    
  • 用JavaScript直接点击元素
    绕过Selenium的可见性检查,直接通过JS触发元素的点击事件:

    next_btn = driver.find_element(By.ID, 'pager_next_page_id')
    driver.execute_script("arguments[0].click();", next_btn)
    
  • 等待元素完全可见
    如果元素是因页面加载延迟导致暂时不可见,可使用显式等待等待元素可见:

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    
    next_btn = WebDriverWait(driver, 10).until(
        EC.visibility_of_element_located((By.ID, 'pager_next_page_id'))
    )
    next_btn.click()
    
  • 排查遮挡元素
    检查页面是否有弹窗、遮罩层等元素遮挡了目标按钮,若有需先关闭或移除遮挡元素,再执行点击操作。

内容的提问来源于stack exchange,提问作者MrMrProgrammer

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.05 01:33:14