Python 在 PyCharm CE 中使用 Selenium

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24333330/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 04:26:48  来源:igfitidea点击:

Using Selenium with PyCharm CE

pythonseleniumselenium-webdriver

提问by DavidJB

I'm trying to use Selenium with PyCharm CE. I have installed Selenium using pip install Selenium and I'm able to use it via the terminal however when I try to use it with PyCharm I get an import error

我正在尝试将 Selenium 与 PyCharm CE 一起使用。我已经使用 pip install Selenium 安装了 Selenium,并且可以通过终端使用它,但是当我尝试将它与 PyCharm 一起使用时,出现导入错误

ImportError: cannot import name webdriver

Would anyone know why Selenium would work using the terminal but not even be able to import the module using PyCharm..?

有谁知道为什么 Selenium 可以使用终端工作,但甚至无法使用 PyCharm 导入模块..?

Thanks,

谢谢,

回答by preetam

If you have pip <http: www.pip-installer.org="">_ on your system, you can simply install or upgrade the Python bindings::

如果您pip <http: www.pip-installer.org="">的系统上有_,您可以简单地安装或升级 Python 绑定:

pip install -U selenium

pip install -U 硒

Alternately, you can download the source distribution from PyPI <http: pypi.python.org="" pypi="" selenium="">_ (e.g. selenium-2.46.tar.gz), unarchive it, and run::

或者,您可以从PyPI <http: pypi.python.org="" pypi="" selenium="">_下载源发行版(例如 selenium-2.46.tar.gz),将其解压缩,然后运行:

python setup.py install

python setup.py 安装

回答by FunkSoulBrother

You can press alt+enter on the library that's missing in the code (most likely it will be underscored with a squiggly red line. select "import lib" from the popup menu. Pycharm will download and set it up.

您可以在代码中缺少的库上按 alt+enter 键(很可能会用波浪形红线下划线。从弹出菜单中选择“导入库”。Pycharm 将下载并设置它。

Good luck.

祝你好运。

回答by Atul

This can be resolved in two ways:

这可以通过两种方式解决:

  1. pip install selenium

  2. Go to Pycharm -> Perform (Cntrl + Alt + S) -> Select Project Interpreter -> Click on (+) icon -> Search for Selenium -> Select and Install Package -> Apply -> Ok

  1. pip 安装硒

  2. 转到 Pycharm -> Perform (Cntrl + Alt + S) -> 选择项目解释器 -> 单击 (+) 图标 -> 搜索 Selenium -> 选择并安装包 -> 应用 -> 确定

enter image description here

在此处输入图片说明

回答by Aashar Wahla

To import web driver you will have to write

要导入网络驱动程序,您必须编写

from selenium import webdriver

this will solve your problem

这将解决您的问题