静态 类方法 自动化-四种定位方法
#实例方法,静态方法,类方法的区别#类方法@1.参数的区别实例方法:定义实例方法时最少有一个形参--实例对象,通常self类方法:定义类方法时最少有一个形参--类对象,通常用cls静态方法:定义静态方法时可以不用定义形参2.方法定义时添加装饰器的区别实例方法:不需要添加装饰器类方法:需要添加装饰器--》classmethod# 静态方法@staticmethod
# class Dog:#
# age=3
# # def __init__(self):
# # self.name='张三'
# def __init__(self,name):
# self.name=name
# def run(self):
# # print('%s岁的%s正在跑步'%(self.age,self.name))
# print('{}岁的{}正在跑步'.format(self.age,self.name))
# @classmethod#类方法
# def eat(cls):
# # print(cls.name)
# print("夏油杰{}岁了".format(cls.age))
# @staticmethod#静态方法
# def sleep(name):
# print('{}在睡觉'.format(name))
# d=Dog('五条悟')#创建对象
# d.run()
# Dog.run(d)
# Dog.eat()
# Dog.sleep(name='无条悟')
# d.sleep(name='无量空处')
# d.eat()
# class Father():
# def __init__(self,car):
# self.car=car
# def rich(self):
# print("爸爸给好大儿买了{}".format(self.car))
# def house(self):
# print("有地有楼")
# f=Father("溜冰鞋")
# b=Father('蓝火AK47')
# f.rich()
# Father.rich(b)
#
# class BigSon(Father):
# def girl(self):
# print("给自己买了一辆{}".format(self.car))
# f=Father("滑板车")
# f.rich()
# b=BigSon("揽胜")
# b.girl()
# class Teacher():
# def __init__(self,name):
# self.name=name
# def Name(self):
# print('my teacher is {}'.format(self.name))
# class Myself(Teacher):
# def Name(self):
# print('i am {}'.format(self.name))
# f=Myself('蔷姐')
# f.Name()
# class Mother():
# def __init__(self,work):
# self.work=work
# def Work(self):
# # def __init__(self,something):
# # self.something=something
# # def bobby(self):
# print("mama love {}".format(self.something))
# class Farher():
# def __init__(self,work):
# self.work=work
# def Work(self):
# print('farher work is {}'.format(self.work))
# class Myself(Farher,Mother):
# pass
# # def __init__(self,work=None,something=None):
# # Farher.__init__(self,work)
# # Mother.__init__(self,something)
#
# m=Myself('test1')
# # m.bobby()
# m.Work()
# print(Myself.mro())
from selenium import webdriver#导入seleniumku引用到webdriver
import time
driver=webdriver.Chrome()#通过webdriver调用chrome生成一个浏览器
driver.get('https://www.baidu.com')#通过浏览器对象调用get方法打开测试地址
# time.sleep(2)
#1.id定位方法
# driver.find_element_by_id("kw").send_keys('python')
# a=driver.find_element_by_id("kw")
# a.send_keys("why")
#2.name 定位方法
# driver.find_element_by_name("wd").send_keys("mysql")
#3.class定位方法
# driver.find_element_by_class_name("s_ipt").send_keys("linux")
#4.xpath定位方法
#相对路径
# driver.find_element_by_xpath('//*[@id="kw"]').send_keys("武汉")
# driver.find_element_by_xpath('//*[@name="wd"]').send_keys("武汉")
#两个"//" 代表相对路径,*通配符配任意签名
# 组合定位
# driver.find_element_by_xpath('//*[@id="kw" and @name="wd"]').send_keys("误会")
driver.find_element_by_xpath('//*[@id="form"]/span/input').send_keys("误会")
#先定位到它上一级父级定位
#绝对路径
# html
页:
[1]