如何使VSCode识别硒?

时间:2020-10-19 15:35:16

标签: python selenium selenium-webdriver visual-studio-code

我尝试了几种不同的方式安装Selenium,并使用命令提示符导航到多个不同的文件夹。但是每次安装时,都会得到以下信息:

Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: selenium in c:\users\(me)\appdata\roaming\python\python38\site-packages (3.141.0)
Requirement already satisfied: urllib3 in c:\users\(me)\appdata\roaming\python\python38\site-packages (from selenium) (1.25.10)

当我在VSCode中尝试基本测试时,我得到了:

<ipython-input-1-8510f5dbbe17> in <module>
----> 1 from selenium import webdriver
      2 driver = webdriver.Chrome()
      3 driver.get('https://www.nasa.gov')
      4 headlines = driver.find_elements_by_class_name("headline")
      5 for headline in headlines:

ModuleNotFoundError: No module named 'selenium' 

我也尝试使用NuGet安装Selenium.Webdriver,但出现此错误:

Cannot find any .csproj or .fsproj for your project! Please fix this error.

我肯定会忽略一些基本知识。什么事?

1 个答案:

答案 0 :(得分:1)

建议您使用“ keypoints”在当前的python environment中安装模块“ pip”:

  1. 检查安装工具“ selenium”是否来自当前选择的环境:

    enter image description here

  2. 使用命令“ pip”或“ pip install selenium”安装模块。

  3. 检查安装是否成功:“ pip3 install selenium”或“ pip list

    enter image description here

  4. 运行:

    enter image description here

更多参考资料:Use Python in VSCode