学习课本:Selenium 2自动化测试实战 基于Python语言
1、环境部署
使用Python 3的版本,IDLE工具使用PyCharm,浏览器使用Chrome
安装selenium
①:使用pip安装:在cmd中直接执行命令 pip install selenium
②:用PyCharm直接添加模块,如图,点击+号可以添加模块
2、尝试编写第一个自动化脚本
因为使用谷歌浏览器,所以需要使用谷歌驱动chromdriver.exe
代码如下:
from
selenium
import
webdriver
#import os
#path = os.path.abspath(r'C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe')
dr = webdriver.Chrome()
dr.get(
'https://www.baidu.com'
)
dr.find_element_by_id(
"kw"
).send_keys(
"selenium2"
)
dr.find_element_by_id(
"su"
).click()
dr.close()
如果执行成功,则说明环境部署正确