20170920学习笔记Selenium 2 第二章测试环境搭建

来源:互联网 发布:淘宝网精品推荐棉拖鞋 编辑:程序博客网 时间:2024/05/22 12:54
2.1Windows下的环境搭建
python的版本选择python3
2.1.1安装python
访问Python官网安装。注意勾选Add python to path。选项。
2.1.2安装setuptools与Pip
pip已经集成在python最新安装包里。python3不支持setuptools。
2.1.3安装selenium
通过pip指令安装selenium。
cmd下,pip install Selenium 会默认安装最新版。注意,部分机器需要在管理员权限的命令行。
2.1.4ActivePython
是ActiveState公司推出的Python专用编程和调试工具。
访问ActivePython官网下载。https://www.activestate.com/activepython/downloads
2.2Ubuntu环境安装
python已经集成在Ubuntu中。pip也存在软件库中。执行命令调取安装。
sudo apt-get pip
同理 安装Selenium ,命令行需要root权限。
sudo apt-get install selenium

2.3使用IDLE编写PYthon。
开发前需要找到合适的 IDE(Intergrated Development Environment) 集成开发环境。
python 自带的IDLE
1.tab 键自动补全。输入两个字母,点击tab键可以自动弹出下拉框补全。
2. 组合键 alt+p 回退到上一次编辑的python代码。 alt+n 可以前进。

2.4编写第一个自动化脚本
打开浏览器,百度网页。输入文案并查找。
打开浏览器需要安装浏览器驱动
火狐 https://github.com/mozilla/geckodriver/releases/tag/v0.19.0
谷歌https://sites.google.com/a/chromium.org/chromedriver/
Microsoft WebDriverhttps://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/
IE http://selenium-release.storage.googleapis.com/index.html


#coding=utf-8

fromselenium importwebdriver

#driver = webdriver.Ie()
#driver = webdriver.Firefox()
driver = webdriver.Chrome()


driver.get("http://www.baidu.com")

driver.find_element_by_id("kw").send_keys("Selenium3")
driver.find_element_by_id("su").click()
# driver.quit()

阅读全文
0 0
原创粉丝点击