python selenium环境搭建笔记
来源:互联网 发布:大学java专业入门课程 编辑:程序博客网 时间:2024/06/07 05:08
推荐一:《使用Python学习selenium测试工具》
推荐二:《selenium官方文档》
- 安装python(很简单,网上很多教程)
- 安装selenium
- DOS窗口输入:python -m pip install selenium
- 查看安装的selenium版本号
- 打开命令行
- 进入python环境,输入:
python
- 导入selenium包:
import selenium
- 查看版本号:
selenium.__version__
- 安装chrome驱动
- 下载chrome驱动
- 解压后把chromedriver.exe文件放到chrome安装目录里
- 把chrome安装目录的路径配置到环境变量path中
- eclipse下的pydev安装
- 可以用其他编辑工具,pycharm等
- 验证selenium是否安装成功
# TestSelenium.py#!/user/bin/env python#encoding: utf-8from selenium import webdriver# 此处注释的代码可能出现调起firefox不能正常请求get地址# 这里要注意:selenium和firefox版本匹配# 我这里装的是selenium 2.53.6 + firefox45.3# 之前装的firefox48.0执行时会有异常,群友建议45.0以下# # browser = webdriver.Firefox()# browser.get(url="https://www.baidu.com")# browser.close()chrome_driver_path = r"C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe"browser = webdriver.Chrome(chrome_driver_path)browser.get("https://www.baidu.com")print(browser.title)browser.find_element_by_id("kw").send_keys("gg")browser.find_element_by_id("su").click()
到这里selenium基本环境已经搭建完成了。
搭建过程中遇到个问题:
未安装chrome驱动时,直接用webdriver调起firefox,使用其get方法传参时总是报错;
Traceback (most recent call last): File "E:\fish\phpWeb\eclipse\MyPydev\mysrc\test.py", line 7, in <module> browser.get("https://www.baidu.com")TypeError: get() missing 1 required positional argument: 'url'
webdriver文件中,关于get的定义:
def get(self, url): """ Loads a web page in the current browser session. """ self.execute(Command.GET, {'url': url})
- 不知道为什么错误提示需要传两个参数?另一个问题,这两个参数应该怎么传,才能保证程序正常运行?
- 经群友指点,这里定义的两个参数,其实并不是说调用时要传两个
- 这里的self是python定义函数的一种默认形式,类似于java的this
- 最后问题定位到:firefox浏览器版本不匹配 + 调用Firefox时,要加“()”
0 0
- python selenium环境搭建笔记
- [mac笔记]Mac搭建python+selenium环境
- Python + Selenium环境搭建
- selenium+python搭建环境
- Selenium+python环境搭建
- Selenium+Python 环境搭建
- python selenium 环境搭建
- selenium+python环境搭建
- Python+Selenium环境搭建
- selenium python环境搭建
- Python+selenium环境搭建
- selenium+Python环境搭建
- 搭建selenium + python环境
- 搭建Python+Selenium环境
- selenium + python环境搭建
- selenium + python环境搭建
- selenium + Python 自动化环境搭建
- Selenium+python+eclipse环境搭建
- AFNetworking 2.x 修改适配IPV6
- hdu5734——Acperience(数学推导)
- POJ 2528 Mayor's posters 线段树+离散化技巧
- 互联网金融之量化投资深度文本挖掘——附源码文档
- POJ 1961 KMP
- python selenium环境搭建笔记
- poj 1416 Shredding Company
- POJ 2406 Power Strings KMP
- [总结]FFMPEG视音频编解码零基础学习方法
- 清理Xcode缓存
- Ubuntu如何安装Adobe Flash Player
- 在对象之间搬移特性(一)
- javascript 原生进行时
- 跑男寻宝游戏,AR,及基于地理位置的移动广告技术