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模式可以大大提高测试用例的维护效率. 传 ...
随机推荐
- linux与Windows使用编译区别及makefile文件编写
一.Windows与:Linux嵌入式开发区别 Windows下编辑.编译.执行 编辑: sourceInsight:ADS: 编译:指定链接地址,指定链接顺序,编译 执行:烧写到单板再启动 Linu ...
- Android开发之动态添加控件
动态添加TextView控件: 一:创建一个Android project项目 activity_main.xml文件: 1.用两个LinearLayout布局分别包裹一对TextView,EditT ...
- C与C++的部分区别
1.函数无形参情况 void test() { } int main() { test(,); ; } 在C语言中形参括号没有参数时代表接受任意多的参数,而在C++语言中代表void(无参数) 所以上 ...
- windows编程之窗口抖动
仅仅让黑窗口抖动以供小白娱乐 #include<stdio.h> #include<windows.h> int main() { RECT rect;//RECT定义了一个矩 ...
- 网站钓鱼的方法 和 xss
获取cookie利用代码cookie.asp <html> <title>xx</title> <body> <%testfile = Serve ...
- flume-source
1.1 Avro Source 监听Avro端口,从Avro client streams接收events.要求属性是粗体字.利用Avro Source可以实现多级流动.扇出流.扇入流等效果.另外也可 ...
- 学习笔记之1001 Inventions That Changed the World
1001 Inventions That Changed the World: Jack Challoner: 9780764161360: Amazon.com: Books https://www ...
- java 泛型 checkcast
我们来看一段代码 public class Test3 { public static void main(String args[]) throws IllegalAccessException, ...
- text clf rnn
#!/usr/bin/env python # coding=utf- import numpy as np import pandas as pd import re from bs4 import ...
- docker容器内外相互拷贝数据
从宿主机上拷贝文件到容器内 注意:一下红色字体为宿主机文件 docker cp 文件 容器名:目录 # docker cp httpd-2.4.34.tar.gz node4:/opt/ 从宿主机上拷 ...