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

使用Selenium+Python开发YouTube定时上传机器人遇元素不可交互错误

YouTube定时上传机器人:解决ElementNotInteractableException问题

针对你遇到的日期输入框无法交互的问题,以下是几种可行的解决思路和代码实现:

1. 等待元素完全可交互

页面加载或日期选择器展开需要时间,直接定位元素可能导致它还未处于可交互状态。使用WebDriverWait等待元素可点击后再操作:

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

date_picker = driver.find_element(By.ID, 'datepicker-trigger').click()
# 等待输入框可交互,超时时间10秒
date_input = WebDriverWait(driver, 10).until(
    EC.element_to_be_clickable((By.CSS_SELECTOR, 'input.style-scope.tp-yt-paper-input'))
)
date_input.clear()
date_input.send_keys("Nov 15, 2022")
date_input.send_keys(Keys.ENTER)

2. 先激活外层容器再操作输入框

YouTube的输入框嵌套在iron-input组件内,可能需要先点击外层组件激活输入状态:

date_picker = driver.find_element(By.ID, 'datepicker-trigger').click()
# 等待并点击外层iron-input
iron_input = WebDriverWait(driver, 10).until(
    EC.element_to_be_clickable((By.ID, 'input-5'))
)
iron_input.click()
# 再定位内部输入框进行操作
date_input = driver.find_element(By.CSS_SELECTOR, 'input.style-scope.tp-yt-paper-input')
date_input.clear()
date_input.send_keys("Nov 15, 2022")
date_input.send_keys(Keys.ENTER)

3. 用JavaScript直接设置输入值

如果常规交互方法失效,可以通过JavaScript直接修改输入框的value属性,并触发页面的输入/变更事件:

date_picker = driver.find_element(By.ID, 'datepicker-trigger').click()
date_input = WebDriverWait(driver, 10).until(
    EC.presence_of_element_located((By.CSS_SELECTOR, 'input.style-scope.tp-yt-paper-input'))
)
# 直接设置输入框值
driver.execute_script("arguments[0].value = 'Nov 15, 2022';", date_input)
# 触发输入事件,让页面识别值已修改
driver.execute_script("arguments[0].dispatchEvent(new Event('input'));", date_input)
driver.execute_script("arguments[0].dispatchEvent(new Event('change'));", date_input)
# 按回车确认
date_input.send_keys(Keys.ENTER)

额外检查点

  • 确认日期选择器弹窗完全展开,没有被页面遮罩层、弹窗遮挡;
  • 检查页面是否有其他需要处理的提示框(如权限提示),避免干扰元素交互。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.12 11:31:40