Python_selenium中类函数模块的简单介绍
Python_selenium中类函数模块的简单介绍
一、demo1.py的代码如下所示
#coding:utf-8
class ClassA(object):
string = "这是一个字符串"
def instancefunc(self):
print "这是一个实例方法"
print self
@classmethod
def classfuc(cls):
print "这是一个类方法"
print cls
@staticmethod
def staticfuc():
print '这是一个静态方法'
test=ClassA() #初始化一个ClassA的对象,test是实例ClassA的实例对象
test.instancefunc()#对象调用实例方法
test.staticfuc()#对象调用静态方法
test.classfuc()#对象调用类方法
print test.string#对象调用类变量
ClassA.instancefunc(test)#类调用实例方法,需要带参数,test为实例参数
ClassA.instancefunc(ClassA)#类调用实例方法,需要带参数,ClassA为类参数
ClassA.staticfuc()#类调用静态方法
ClassA.classfuc()#类调用类方法
二、备注
1. 类的定义,class开头的就表示这是一个类,小括号里面的,表示这个类的父类,涉及到继承,默认object是所有类的父类。python中定义类
小括号内主要有三种:1. 具体一个父类,2. object 3. 空白
2. 函数或方法的定义, def开头就表示定义一个函数,方法包括,实例方法,类方法,静态方法,注意看类方法和静态方法定义的时候上面有一个@标记。
3. 对象调用方法和类调用方法的使用。
三、实际测试脚本
#coding:utf-8
from selenium import webdriver
import time
class BaiduSearch(object):
driver=webdriver.Firefox()
driver.maximize_window()
driver.implicitly_wait(8)
def open_baidu(self):
self.driver.get("https://www.baidu.com/")
time.sleep(2)
def test_search(self):
self.driver.find_element_by_id("kw").send_keys("selenium")
time.sleep(2)
print self.driver.title
try:
assert 'selenium' in self.driver.title
print 'test pass'
except Exception as e:
print 'test fail'
self.driver.quit()
baidu=BaiduSearch() #初始化一个BaiduSearch的对象,baidu是BaiduSearch的实例对象
baidu.open_baidu()#对象调用实例方法
baidu.test_search()#对象调用实例方法
详情参考:http://blog.csdn.net/u011541946/article/details/70157011
Python_selenium中类函数模块的简单介绍的更多相关文章
- python+selenium之中类/函数/模块的简单介绍和方法调用
# coding=utf-8 class ClassA (object): string1 = "这是一个字符串." def instancefunc(self): print ( ...
- node.js当中的http模块与url模块的简单介绍
一.http模块的简单介绍 node.js当中的http内置模块可以用于创建http服务器与http客户端. 1.引包 const http = require('http'); 2.创建http服务 ...
- Spring IOC模块的简单介绍
首先,本人正在学习spring,这是一点心得体会,所以本文中会有不足.错误之处,欢迎各位大佬进行指点. 其次对于框架而言,知道反射是很重要,所以建议在学会反射了后在去看看框架. Spring:是企业级 ...
- python 定义函数关键字def 简单介绍
一 在类中定义的def # python中def 是用来干什么的? # 可以定义函数,就是定义一个功能. class People(): def __init__(self): print(&quo ...
- 从0开始学爬虫7之BeautifulSoup模块的简单介绍
参考文档: https://www.crummy.com/software/BeautifulSoup/bs4/doc.zh/ # 安装 beautifulsoup4 (pytools) D:\pyt ...
- formidable处理提交的表单或文件的简单介绍
一般来说,客户端向服务端提交数据有GET和POST这两种方式,在之前的文章node.js当中的http模块与url模块的简单介绍当中我们可以知道通过req.url与url模块的配合处理可以快速得到客户 ...
- formidable处理提交的表单或图片文件的简单介绍
一般来说,客户端向服务端提交数据有GET和POST这两种方式,在之前的文章node.js当中的http模块与url模块的简单介绍当中我们可以知道通过req.url与url模块的配合处理可以快速得到客户 ...
- 【Python】operator 模块简单介绍
简单介绍几个常用的函数,其他的请参考文档. operator.concat(a, b) **operator.__concat__(a, b)** 对于 a.b序列,返回 a + b(列表合并) -- ...
- Python模块:operator简单介绍
Python官方文档地址:https://docs.python.org/3.6/library/operator.html?highlight=operator Operator提供的函可用于对象比 ...
随机推荐
- vue vue-router 使用注意事项
1.$router和$route区别 this.$router 访问路由器,实现路由的跳转等功能. this.$route 实现访问当前路由,$route.query (如果 URL 中有查询参数). ...
- ES6 iterator 迭代器
iterator使用TypeScript 的描述: interface Iterable { [Symbol.iterator]() : Iterator, } interface Iterator ...
- HTML5中标记与特殊属性
不允许写结束标记的元素有(只允许<元素/>): area.base.br.col.command.embed.hr.img.input. keygen.link.meta.param.so ...
- CSS-常用媒体查询
width:视口宽度.height:视口高度.device-width:渲染表面的宽度(对我们来说,就是设备屏幕的宽度).device-height:渲染表面的高度(对我们来说,就是设备屏幕的高度). ...
- ip地址库选择
目前市面上常用的ip地址库,有以下几种 1,新浪的api接口(限制未知)http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js& ...
- public_brokers
This page is an effort to list the publically-accessible MQTT brokers, often useful for testing and ...
- Mobicents记录1:如何搭建和运行mobicents3.0环境(基于jboss7.2)
网上能查到的mobicents的资料都是基于比较老的版本,而官网现在已经更新到3.0的版本,很多资料都已经无效,所以把自己的摸索过程记录下来,以便后来者能少走点弯路,快速上手. 闲言少叙,开始正文.. ...
- linux释放内存命令
1.首先查看linux内存使用 #free -m 2.把内存数据同步到硬盘#sync 3.修改 /proc/sys/vm/drop_caches文件 #echo 3 > /proc/sys/vm ...
- maven分开打包jar文件和依赖jar包和资源文件
<properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> &l ...
- FPGA的图像处理技术
最近一段时间一直在研究基于FPGA的图像处理,乘着EEPW这个机会和大家交流一下,自己也顺便总结一下.主要是为了大家对用FPGA做图像处理有个感性的认识,如果真要研究的话就得更加深入学习了.本人水平有 ...