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模式可以大大提高测试用例的维护效率. 传 ...
随机推荐
- 关于div
<article id="a"> <div class="a1"></div> <div class="a2 ...
- python MySQL-Slave从服务器状态检测脚本
#!/bin/bash mysql -e "show slave status\G" > mysql_status.txt array=($(egrep 'Slave_IO_ ...
- Windows Azure Virtual Network (12) 虚拟网络之间点对点连接VNet Peering
<Windows Azure Platform 系列文章目录> 在有些时候,我们需要通过VNet Peering,把两个虚拟网络通过内网互通互联.比如: 1.在订阅A里的Virtual N ...
- if的各种真假判断
- 基于Kafka消息驱动最终一致事务(一)
基本可用软状态最终一致事务 本用例分两个数据库分别是用户库和交易库,不使用分布式事务,使用基于消息驱动实现基本可用软状态最终一致事务(BASE).现在说明下事务逻辑演化步骤,尊从CAP原则,即分布式系 ...
- levenshtein函数
Levenshtein算法已在部分DBMS中实现. (例如:PostgreSQL:http://www.postgresql.org/docs/9.1/Static/fuzzystrmedi.html ...
- Java学习——上转型与下转型对象
上转型:重写父类方法才调用子类方法,其他仍用父类的,包括被子类隐藏的父类成员变量,而且不能调用子类新增的成员变量和成员方法. 下转型:只能是转上去的才能转下去.下转型类似于该子类直接继承父类. pac ...
- MySQL并发复制系列一:binlog组提交 (转载)
http://blog.csdn.net/woqutechteam/article/details/51178803 MySQL Binary log在MySQL 5.1版本后推出主要用于主备复制的 ...
- MFC (如何通过点击botton打开一个文件夹/文件)
1.建一个MFC的工程,类型为基于对话框.在工具箱里拖进去一个button按键,如下图. 2.双击button1按键就可以进入到点击button1后要执行操作的代码,编写如下代码实现网页/文件夹或者文 ...
- classpath路径配置
在很多Apache的框架中,经常遇见配置classpath情况,但是都没有认真研究过classpath,下面是对classpath的解析. classpath: 是指编译过后的的classes目录 对 ...