py库: Selenium (自动化测试)
http://blog.csdn.net/liujingqiu/article/details/50458553
http://www.cnblogs.com/zhaof/p/6953241.html python爬虫从入门到放弃(八)之 Selenium库的使用 2017-10-18
https://www.youtube.com/watch?v=roTwhVIHkAo
首先需要一个浏览器供python使用:Chormedriver.exe
http://download.csdn.net/download/r455678/9713526 墙内可以这里下载2.25版本的
- http://www.seleniumhq.org/download/ selenium官网 页面内查找chrome(同理,可以查找其它浏览器的driver)
- https://sites.google.com/a/chromium.org/chromedriver/ google相关页面
- https://chromedriver.storage.googleapis.com/index.html?path=2.35/ google下载页,下载:
- https://chromedriver.storage.googleapis.com/2.35/chromedriver_win32.zip
下载后保存在 C:\Python3\Scripts\Chormedriver.exe
先来个例子:
# -*- coding: utf-8 -*-
from selenium import webdriver
import time browser = webdriver.Chrome() # Chrome浏览器
#browser = webdriver.Firefox() # Firefox浏览器
browser.get("http://www.baidu.com")
browser.find_element_by_id("kw").send_keys("自动化测试")
time.sleep(5)#休息5秒
browser.close()
browser.quit()
from selenium import webdriver
import time browser = webdriver.Chrome() # Chrome浏览器
# browser = webdriver.Firefox() # Firefox浏览器
browser.get("https://morvanzhou.github.io")
browser.find_element_by_link_text(u"赞助").click()
time.sleep(2)
browser.find_element_by_link_text("About").click()
time.sleep(2)
browser.find_element_by_link_text(u"教程 ▾").click()
time.sleep(2)
browser.find_element_by_link_text(u"推荐学习顺序").click()
time.sleep(2)
html = browser.page_source
browser.get_screenshot_as_file("zz123.png") time.sleep(10) # 休息5秒
browser.close()
browser.quit()
常用的查找元素方法:
- find_element_by_name
- find_element_by_id
- find_element_by_xpath
- find_element_by_link_text
- find_element_by_partial_link_text
- find_element_by_tag_name
- find_element_by_class_name
- find_element_by_css_selector
示例: 其它例子去这里看:http://www.cnblogs.com/zhaof/p/6953241.html
from selenium import webdriver
browser = webdriver.Chrome()
browser.get("http://www.zhihu.com/explore") #获取元素属性 get_attribute('class')
logo = browser.find_element_by_id('zh-top-link-logo')
print(logo)
print(logo.get_attribute('class')) #获取文本值 text
input = browser.find_element_by_class_name('zu-top-add-question')
print(input.text) # 执行js
# browser.execute_script('window.scrollTo(0, document.body.scrollHeight)')
# browser.execute_script('alert("To Bottom")') #获取:id, 位置:location , 标签名:tag_name, size
input = browser.find_element_by_class_name('zu-top-add-question')
print(input.id)
print(input.location)
print(input.tag_name)
print(input.size)
...
py库: Selenium (自动化测试)的更多相关文章
- Python网络数据采集7-单元测试与Selenium自动化测试
Python网络数据采集7-单元测试与Selenium自动化测试 单元测试 Python中使用内置库unittest可完成单元测试.只要继承unittest.TestCase类,就可以实现下面的功能. ...
- Jenkins持续集成项目搭建与实践——基于Python Selenium自动化测试(自由风格)
Jenkins简介 Jenkins是Java编写的非常流行的持续集成(CI)服务,起源于Hudson项目.所以Jenkins和Hudson功能相似. Jenkins支持各种版本的控制工具,如CVS.S ...
- Selenium自动化测试Python二:WebDriver基础
WebDriver基础 欢迎阅读WebDriver基础讲义.本篇讲义将会重点介绍Selenium WebDriver的环境搭建和基本使用方法. WebDriver环境搭建 Selenium WebDr ...
- Selenium自动化测试基础
如有任何学习问题,可以添加作者微信:lockingfree 目录 Selenium自动化测试基础 Selenium自动化测试第一天(上) Selenium自动化测试第一天(下) Selenium自动化 ...
- JavaScript(Node.js)+ Selenium自动化测试
Selenium is a browser automation library. Most often used for testing web-applications, Selenium may ...
- selenium自动化测试(1):环境搭建
Selenium是一款优秀的WEB自动化测试工具,它功能强大,易于使用,支持多种平台.多种浏览器和多种开发语言.这里介绍使用python+selenium进行自动化测试的一些基础知识. 在Window ...
- Selenium自动化测试,接口自动化测试开发,性能测试从入门到精通
Selenium自动化测试,接口自动化测试开发,性能测试从入门到精通Selenium接口性能自动化测试基础部分:分层自动化思想Slenium介绍Selenium1.0/2.0/3.0Slenium R ...
- Selenium自动化测试框架入门整理
关注嘉为科技,获取运维新知 本文主要针对Selenium自动化测试框架入门整理,只涉及总体功能及框架要点介绍说明,以及使用前提技术基础要求整理说明.作为开发人员.测试人员入门参考. 本文参考:Se ...
- Selenium自动化测试Python一:Selenium入门
Selenium入门 欢迎阅读Selenium入门讲义,本讲义将会重点介绍Selenium的入门知识以及Selenium的前置知识. 自动化测试的基础 在Selenium的课程以前,我们先回顾一下软件 ...
- selenium自动化测试框架之PO设计模式
面向对象的特性:封装.继承.多态.在自动化中一样适用,Selenium自动化测试中有一个名字常常被提及PageObject(思想与面向对象的特性相同),通过PO模式可以大大提高测试用例的维护效率. 传 ...
随机推荐
- 5分钟搭建 nginx +php --------------(LNMP)新手专用
5分钟搭建 nginx +php --------------(LNMP)新手专用 2014-11-14 16:48 88876人阅读 评论(2) 收藏 举报 版权声明:本文为博主原创文章,未经博主允 ...
- Django REST framework 总结(附源码剖析)
Django 的 CBV&FBV Django FBV, function base view 视图里使用函数处理请求 url url(r‘^users/‘, views.users), v ...
- WPF Demo18 路由事件
using System.Windows; namespace 路由事件2 { public class Student { ////声明并定义路由事件 //public static readonl ...
- <亲测>阿里云centos7安装redis
安装redis yum install redis 启动redis systemctl start redis.service 设置redis开机启动 systemctl enable redis.s ...
- 使用keytool 生成数字keystore
生成本地证书 在密钥库中生成本地数字证书:需要提供身份.加密算法.有效期等信息: keytool指令如下,产生的本地证书后缀名为:*.keystore keytool -genkeypair -key ...
- HTTP之Cookie
cookie是什么 浏览器存储在本地电脑上的一小段文本文件,cookie的存在主要是为了解决http协议无状态的问题,例如通过cookie来判断用户的登录状态,是否是某一个用户等. cookie的结构 ...
- 【转】SOA架构设计经验分享—架构、职责、数据一致性
1.背景介绍 最近一段时间都在做系统分析和设计工作,面对的业务是典型的重量级企业应用方向.突然发现很多以往觉得很简单的问题变得没有想象的那么容易,最大的问题就 是职责如何分配.论系统架 ...
- bundle adjustment 玩具程序
结合 bundle adjustment原理(1) 和 Levenberg-Marquardt 的 MATLAB 代码 两篇博客的成果,调用MATLAB R2016a中 bundleAdjustmen ...
- java之基本数据类型
11,java里面有没有long double类型或者比double更精度的? =========== 11,java里面有没有long double类型或者比double更精度的? java的基本数 ...
- [UE4]先报告后广播模式
解决客户端射击,在服务器端和其他客户端看不到的问题. 一.把要广播的操作封装成一个事件(函数不支持网络属性),选择“多路传送” 二.创建一个事件,选择“在服务器上运行” 总结:从客户端执行的事件报告到 ...