You need to enable JavaScript to run this app. VSCode中Pylint报Python Selenium导入Keys的import-error但程序正常运行
优惠活动
大模型
产品
解决方案
定价
更多

VSCode中Pylint报Python Selenium导入Keys的import-error但程序正常运行

问题描述

在代码行 from selenium.webdriver.common.keys import Keys 处收到Pylint导入报错,代码本身可正常运行,运行表现与无报错时完全一致。

具体报错内容:

"无法导入 'selenium.webdriver.common.keys' pylint(import-error)。"

已完成的排查:

  • 确认Keys的大小写书写完全符合规范,排除大小写错误这类常见导入问题诱因
  • 参考过多类同场景的导入问题公开排查记录,未匹配到适配当前场景的解法

环境说明

当前使用编辑器为VSCode,已安装Python、MagicPython扩展。
用于排查问题的完整测试代码如下:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
PATH = "C:/Program Files (x86)/chromedriver.exe"
driver = webdriver.Chrome(PATH)
driver.get("https://amazon.com/")
print(driver.title)
search = driver.find_element_by_id("twotabsearchtextbox")
search.send_keys("glad")
search.send_keys(Keys.RETURN)
time.sleep(5)
driver.quit()

目前暂未定位到问题根源,后续会查阅Selenium官方文档开展排查,问题解决后会同步更新进展,现寻求该问题的排查思路与可落地的解决方案。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.31 07:45:03