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提供的函可用于对象比 ...
随机推荐
- 投票ajax请求代码(点赞代码)
function vote(url, arr) { jq.ajax({ cache: false, async: false, url: url, type: 'post', data: {info_ ...
- ionic 图片加载失败,显示默认图片代替
1.首先编写自定义指令 angular.module('starter.directives', []) //当图片找不到事显示替代图片 .directive("errSrc", ...
- Oracle怎么导出存储过程
Oracle怎么导出存储过程 http://www.myexception.cn/database/1564245.html 导出: 1, 2,点击输出文件,选择要导出文件,选择要导出的目录以及设置导 ...
- 如何取得jvm实例的cpu占用(转)
时间 2014-08-29 17:11:34 田加国的博客 原文 http://www.tianjiaguo.com/programming-language/java-language/如何取得j ...
- angular开发中对请求数据层的封装
代码地址如下:http://www.demodashi.com/demo/11481.html 一.本章节仅仅是对angular4项目开发中数据请求封装到model中 仅仅是在项目angular4项目 ...
- nginx 配置一个文件下载服务
cat openvpn.conf server { listen ; server_name localhost; location / { root /home/openvpn/client_fil ...
- jenkins部署前端node项目实例
Jenkins 分发文件用到rsync命令 在 /etc/passwd中 修改 jenkins 为 /bin/bash jenkins:x:494:494:Jenkins Automation S ...
- oracle 存储过程 ,触发器练习
/*以下代码是对emp表进行显示宽度设置 */col empno for 9999;col ename for a10;col job for a10;col mgr for 9999;col hir ...
- javascript删除数组中的某个元素-----拓展Array 原型方法
Array.prototype.remove = function (dx) { if(isNaN(dx) || dx > this.length) { return false; } var ...
- 深入Activity
此刻,你应该静下心来,在阅读中思考.在思考中进步,读完本篇文章的你一定会有不一样的收获,请让我们共同进步! 核心内容 1.Activity数据交换 2.Activity中的任务栈 3.Activity ...