selenium 4.25.0
pip install selenium
发布时间:
Selenium WebDriver的官方Python绑定
导航
未验证详情
这些详情尚未由 PyPI 验证项目链接
元数据
- 许可证:Apache 软件许可证 (Apache 2.0)
- 要求: Python >=3.8
分类器
项目描述
介绍
Python语言绑定Selenium WebDriver。
selenium包用于从Python自动化网页浏览器交互。
主页: |
|
GitHub: |
|
PyPI: |
|
IRC/Slack: |
支持多个浏览器/驱动程序(Firefox、Chrome、Internet Explorer)以及远程协议。
支持的Python版本
Python 3.8+
安装
如果您系统上有
pip
,您可以直接安装或升级Python绑定pip install -U selenium
或者,您可以从
PyPI
<https://pypi.ac.cn/project/selenium/#files>下载源代码包,解压缩后运行python setup.py install
注意:您可能需要考虑使用
virtualenv
来创建隔离的Python环境。驱动程序
Selenium需要一个驱动程序与所选浏览器交互。例如,Firefox需要
geckodriver
,在以下示例运行之前需要安装。确保它在您的PATH
中,例如,将其放在/usr/bin
或/usr/local/bin
中。如果未执行此步骤,将会出现错误
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
其他支持的浏览器将有自己的驱动程序。以下是一些较受欢迎的浏览器驱动的链接。
Chrome: |
|
Edge: |
https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/ |
Firefox: |
|
Safari: |
https://webkit.org/blog/6900/webdriver-support-in-safari-10/ |
示例 0
打开一个新的Firefox浏览器
在给定的URL加载页面
from selenium import webdriver
browser = webdriver.Firefox()
browser.get('https://selenium.net.cn/')
示例 1
打开一个新的Firefox浏览器
加载Yahoo主页
搜索“seleniumhq”
关闭浏览器
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
browser = webdriver.Firefox()
browser.get('http://www.yahoo.com')
assert 'Yahoo' in browser.title
elem = browser.find_element(By.NAME, 'p') # Find the search box
elem.send_keys('seleniumhq' + Keys.RETURN)
browser.quit()
示例 2
Selenium WebDriver通常用作测试Web应用程序的基础。以下是一个使用Python标准库
unittest
的简单示例import unittest
from selenium import webdriver
class GoogleTestCase(unittest.TestCase):
def setUp(self):
self.browser = webdriver.Firefox()
self.addCleanup(self.browser.quit)
def test_page_title(self):
self.browser.get('http://www.google.com')
self.assertIn('Google', self.browser.title)
if __name__ == '__main__':
unittest.main(verbosity=2)
Selenium Grid(可选)
对于本地Selenium脚本,不需要Java服务器。
要使用远程Selenium,您还需要运行Selenium Grid。有关运行Selenium Grid的信息:https://selenium.net.cn/documentation/grid/getting_started/
要使用Remote WebDriver,请参阅:https://selenium.net.cn/documentation/webdriver/drivers/remote_webdriver/?tab=python
使用源代码!
在线查看源代码
官方 |
贡献
为您的作品创建一个分支
确保已安装
tox
(使用virtualenv
是推荐的)python3.8 -m venv .venv && . .venv/bin/activate && pip install tox
在做出更改并提交之前,执行
tox -e linting
如果tox退出代码为
0
,则提交并推送;否则,修复新引入的破坏。flake8
需要手动修复“black”通常会自动重写断行,但文件未暂存,需要再次暂存。
“isort”通常会自动重写断行,但文件未暂存,需要再次暂存。
项目详情
未验证详情
这些详情尚未由 PyPI 验证项目链接
元数据
- 许可证:Apache 软件许可证 (Apache 2.0)
- 要求: Python >=3.8
分类器
selenium-4.25.0.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 95d08d3b82fb353f3c474895154516604c7f0e6a9a565ae6498ef36c9bac6921 |
|
MD5 | 1f6167cf5723f3f382a0632286e7a913 |
|
BLAKE2b-256 | 0e5ad3735b189b91715fd0f5a9b8d55e2605061309849470e96ab830f02cba40 |
selenium-4.25.0-py3-none-any.whl的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 3798d2d12b4a570bc5790163ba57fef10b2afee958bf1d80f2a3cf07c4141f33 |
|
MD5 | 377b9c9e4d1f8daef1387630f47382af |
|
BLAKE2b-256 | aa85fa44f23dd5d5066a72f7c4304cce4b5ff9a6e7fd92431a48b2c63fbf63ec |