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 (自动化测试)的更多相关文章

  1. Python网络数据采集7-单元测试与Selenium自动化测试

    Python网络数据采集7-单元测试与Selenium自动化测试 单元测试 Python中使用内置库unittest可完成单元测试.只要继承unittest.TestCase类,就可以实现下面的功能. ...

  2. Jenkins持续集成项目搭建与实践——基于Python Selenium自动化测试(自由风格)

    Jenkins简介 Jenkins是Java编写的非常流行的持续集成(CI)服务,起源于Hudson项目.所以Jenkins和Hudson功能相似. Jenkins支持各种版本的控制工具,如CVS.S ...

  3. Selenium自动化测试Python二:WebDriver基础

    WebDriver基础 欢迎阅读WebDriver基础讲义.本篇讲义将会重点介绍Selenium WebDriver的环境搭建和基本使用方法. WebDriver环境搭建 Selenium WebDr ...

  4. Selenium自动化测试基础

    如有任何学习问题,可以添加作者微信:lockingfree 目录 Selenium自动化测试基础 Selenium自动化测试第一天(上) Selenium自动化测试第一天(下) Selenium自动化 ...

  5. JavaScript(Node.js)+ Selenium自动化测试

    Selenium is a browser automation library. Most often used for testing web-applications, Selenium may ...

  6. selenium自动化测试(1):环境搭建

    Selenium是一款优秀的WEB自动化测试工具,它功能强大,易于使用,支持多种平台.多种浏览器和多种开发语言.这里介绍使用python+selenium进行自动化测试的一些基础知识. 在Window ...

  7. Selenium自动化测试,接口自动化测试开发,性能测试从入门到精通

    Selenium自动化测试,接口自动化测试开发,性能测试从入门到精通Selenium接口性能自动化测试基础部分:分层自动化思想Slenium介绍Selenium1.0/2.0/3.0Slenium R ...

  8. Selenium自动化测试框架入门整理

    ​​关注嘉为科技,获取运维新知 本文主要针对Selenium自动化测试框架入门整理,只涉及总体功能及框架要点介绍说明,以及使用前提技术基础要求整理说明.作为开发人员.测试人员入门参考. 本文参考:Se ...

  9. Selenium自动化测试Python一:Selenium入门

    Selenium入门 欢迎阅读Selenium入门讲义,本讲义将会重点介绍Selenium的入门知识以及Selenium的前置知识. 自动化测试的基础 在Selenium的课程以前,我们先回顾一下软件 ...

  10. selenium自动化测试框架之PO设计模式

    面向对象的特性:封装.继承.多态.在自动化中一样适用,Selenium自动化测试中有一个名字常常被提及PageObject(思想与面向对象的特性相同),通过PO模式可以大大提高测试用例的维护效率. 传 ...

随机推荐

  1. Centos升级Python 2.7并安装pip、ipython

    https://www.cnblogs.com/technologylife/p/6242115.html

  2. JavaScript之WebSocket技术详解

    概述 HTTP协议是一种无状态协议,服务器端本身不具有识别客户端的能力,必须借助外部机制,比如session和cookie,才能与特定客户端保持对话.这多多少少带来一些不便,尤其在服务器端与客户端需要 ...

  3. vue element-ui 用checkebox 来模拟选值 1/0

    https://jsfiddle.net/57dz2m3s/12/ 复制 粘贴 打开url就可以看到效果

  4. STL进阶--vector vs deque

    vector class Dog; // 例 1: vector<Dog> vec(6); // vec.capacity() == 6, vec.size() == 6, // 默认构造 ...

  5. C++进阶--不让编译器自动生成类函数

    //############################################################################ /* * 不让编译器自动生成类函数 * * ...

  6. 有趣的background

    前言 background是css的简写形式,可以一次性定义各种背景属性,包括color.image.origin.size,repeat方式等等. background在活动项目中用的还是比较多的, ...

  7. sql server 2008 R2 备份还原到sql 2012

    从sql server 2008 r2备份的在sql server 2012中还原时一直读不到备份文件,然后把2008r2备份文件放到sql 2012的安装路径对应的Backup文件夹后可以读到了,不 ...

  8. JavaScript之图片操作7

    前面总结了很多了有关于图片操作的案例,本次是基于前面的基础,做一个综合的图片轮播效果,需要实现以下功能: 没有任何操作时,图片自动轮播 鼠标悬浮时,图片停止轮播:当鼠标移开,轮播继续 鼠标悬浮时,出现 ...

  9. [转][Oracle][null]

    trim(nvl(ipaddress,'')) != '' 这段SQL 并没有像 MSSQL  IsNull 一样返回不含空白或null 的内容 经尝试发现  trim('') 为 null a fr ...

  10. undefined reference to `__isnan'

    sjs@sjs-virtual-machine:~/work/Onvif$ arm-hisiv100nptl-linux-gcc *.c -lpthread -static -o ../../nfsm ...