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

Selenium调用send_keys报错:Failed to execute 'contains' on 'Node'

解决Supreme结账页Selenium填充姓名框报错的问题

我之前处理过类似的Selenium定位错误,这个unknown error: Failed to execute 'contains' on 'Node': parameter 1 is not of type 'Node'报错,大多是因为页面元素还没完全渲染就绪就尝试定位,或者用了旧版的Selenium定位方法导致底层DOM操作异常。结合你提供的元素信息和代码,给你几个可行的解决方案:

1. 用显式等待替代直接定位

Supreme的页面加载可能有动态资源或者反爬逻辑,直接调用find_element_by_id很容易在元素未就绪时执行,触发DOM相关错误。推荐用WebDriverWait等待元素可交互后再操作:

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

# 初始化Chrome浏览器
driver = webdriver.Chrome()
driver.get("https://www.supremenewyork.com/checkout")

# 等待姓名输入框可点击,最多等待10秒
wait = WebDriverWait(driver, 10)
name_input = wait.until(EC.element_to_be_clickable((By.ID, "order_billing_name")))
name_input.send_keys("Name")

2. 替换已废弃的定位方法

你用的find_element_by_id是Selenium旧版本的API,现在已经被官方标记为废弃,建议使用By.ID的方式定位,避免兼容性问题:

旧代码:

driver.find_element_by_id("order_billing_name").send_keys("Name")

替换为:

driver.find_element(By.ID, "order_billing_name").send_keys("Name")

3. 规避Supreme的反自动化检测

Supreme有反爬机制,可能会检测到Selenium的特征,导致页面渲染异常或者元素无法正常访问。可以给浏览器添加一些配置,隐藏自动化痕迹:

from selenium.webdriver.chrome.options import Options

options = Options()
# 禁用自动化提示
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
# 模拟真实用户代理(可选)
options.add_argument("user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36")

driver = webdriver.Chrome(options=options)
driver.get("https://www.supremenewyork.com/checkout")

排查小技巧

  • 先手动打开页面,检查姓名输入框是否在iframe或者shadow DOM中(从你提供的元素代码看应该不是,但如果有嵌套的话需要切换上下文)
  • 执行代码前,确保页面没有弹窗或者加载遮罩层阻挡元素

内容的提问来源于stack exchange,提问作者A. Skoon

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.22 08:10:29