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提供的函可用于对象比 ...
随机推荐
- taro 请求函数封装
1.项目目录 2.代码 app/src/service/api.js import Taro from '@tarojs/taro' import { HTTP_STATUS } from '../c ...
- centos无法安装vmvare-tools的问题
不要使用 vmware 自带的 tools, 版本太老了. 从这里下载:https://github.com/rasa/vmware-tools-patches.git 直接下载或者使用下面的命令: ...
- 深入annotation
目标: 掌握@Target注释 掌握@Document注释 掌握@inherited注释 之前定义的annotation,如果没有明确声明,可以在任何地方使用: package 类集; @MyDefa ...
- 如何监控Tomcat服务器
如何监控Tomcat服务器 发表于:2009-06-25来源:作者:点击数:2651 标签:tomcatTomcat服务器 在进行 性能测试 时,一般都需要对应用服务器进行监控,监控的指标包括应用服务 ...
- Drupal的错误和异常处理
Drupal在配置阶段的最开始就设置了自己的错误处理器和异常处理器: function _drupal_bootstrap_configuration() { set_error_handler('_ ...
- Getting started with Chrome Dev Editor
转自:https://github.com/GoogleChrome/chromedeveditor/blob/master/doc/GettingStarted.md Installation In ...
- docker build 的 cache 机制
cache 机制注意事项 可以说,cache 机制很大程度上做到了镜像的复用,降低存储空间的同时,还大大缩短了构建时间.然而,不得不说的是,想要用好 cache 机制,那就必须了解利用 cache 机 ...
- Solr4.0使用
http://blog.sina.com.cn/s/blog_64dab14801013k7g.html Solr简介 Solr是一个非常流行的,高性能的开源企业级搜索引擎平台,属于Apache Lu ...
- java 解析webservice 中的soapheader
//从MessageContet中获取头域中的值 public HeaderBean getBeanFromRequest(org.apache.axis2.context.MessageContex ...
- 点滴积累【JS】---JS小功能(操作Table--动态添加删除表格及数据)
效果: 代码: <head runat="server"> <title></title> <style type="text/ ...