4 回答

TA贡献1827条经验 获得超8个赞
不,您不需要为每个项目安装Selenium。安装过程一生只有一次,通过命令行界面使用以下任一命令:
使用点:
pip install selenium
使用pip3:
pip3 install selenium
升级点子
但是,您需要继续定期升级 pip :
在Linux或者苹果系统:
pip install -U pip
在视窗:
python -m pip install -U pip
或者
C:\Users\username>python -m pip install --upgrade pip
Collecting pip
Downloading https://files.pythonhosted.org/packages/5f/25/e52d3f31441505a5f3af41213346e5b6c221c9e086a166f3703d2ddaf940/pip-18.0-py2.py3-none-any.whl (1.3MB)
100% |¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦| 1.3MB 544kB/s
Installing collected packages: pip
Found existing installation: pip 10.0.1
Uninstalling pip-10.0.1:
Successfully uninstalled pip-10.0.1
Successfully installed pip-18.0
升级硒
作为一项强制措施,您需要升级Selenium绑定以与每个稳定版本的发布保持同步,如下所示:
C:\Users\username>pip install -U selenium
Collecting selenium
Downloading https://files.pythonhosted.org/packages/b8/53/9cafbb616d20c7624ff31bcabd82e5cc9823206267664e68aa8acdde4629/selenium-3.14.0-py2.py3-none-any.whl (898kB)
100% |¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦| 901kB 380kB/s
Requirement not upgraded as not directly required: urllib3 in c:\python\lib\site-packages (from selenium) (1.22)
Installing collected packages: selenium
Found existing installation: selenium 3.12.0
Uninstalling selenium-3.12.0:
Successfully uninstalled selenium-3.12.0
Successfully installed selenium-3.14.0
You are using pip version 10.0.1, however version 18.0 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

TA贡献1829条经验 获得超13个赞
每次尝试运行自动化测试时,都需要在 selenium 中初始化浏览器。
driver = webdriver.Chrome('./chromedriver')
driver.get("https://www.python.org")
print(driver.title)
当您尝试从不同的项目运行测试时,您不需要每次都需要初始化浏览器会话时安装 selenium。
也使用pip to installselenium 包。
安装 python 后,尝试使用以下命令使用 pip 命令安装 selenium
pip install selenium
您会在下面找到您的依赖项Python\Lib\site-packages
添加回答
举报