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模式可以大大提高测试用例的维护效率. 传 ...
随机推荐
- C++和extern C
http://blog.csdn.net/gongmin856/article/details/44228453 C语言中的可变参数:va_list ,va_start,va_arg,va_end h ...
- azure 1元试用,如何创建虚拟机等
付了1元后,直接进 https://manage.windowsazure.cn 创建虚拟机即可.
- Mysql 性能优化7【重要】sql语句的优化 慢查询
慢查询时间设置 慢查询日志分析工具 另一个慢查询日志分析工具 如何对sql进行特定的优化
- DS二叉树--左叶子数量
题目描述 计算一颗二叉树包含的叶子结点数量. 左叶子是指它的左右孩子为空,而且它是父亲的左孩子 提示:可以用三叉链表法,也可以用现有算法对两层结点进行判断 建树方法采用“先序遍历+空树用0表示”的方法 ...
- pytest.7.常见套路
From: http://www.testclass.net/pytest/common_useage/ 在使用pytest的时候,下面这些问题我们可能会经常遇到,这里给出官方的解决方案,按照套路来执 ...
- git撤销本地所有未提交的更改
1. git clean -df2. git reset --hard第一个命令只删除所有untracked的文件,如果文件已经被tracked, 修改过的文件不会被回退.而第二个命令把tracked ...
- Hadoop 管理工具HUE配置
机器环境 Ubuntu 14.10 64位 || OpenJDK-7 || Scala-2.10.4 机群概况 Hadoop-2.6.0 || HBase-1.0.0 || Spark-1.2.0 | ...
- Ubuntu 14.10 下安装伪分布式hive-0.14.0
本地独立模式,MySQL作为元数据库 1 安装环境准备 1.1 安装JDK,在安装hadoop时候已经安装了,参考http://www.cnblogs.com/liuchangchun/p/40972 ...
- Socket调用Close后如何终止套接口的问题
setsockopt 设置 SO_LINGER 选项 此选项指定函数close对面向连接的协议如何操作(如TCP).内核缺省close操作是立即返回,如果有数据残留在套接口缓冲区中则系统将试着将这些数 ...
- Hive的安装配置 & 基础指令
Hive 基础命令