python class 類 帶參數(shù)的裝飾器
def three_loop(webpage):
def function(fun):
def wrapper(self, *args, **kwargs):
for i in range(3):
try:
return fun(self, *args, **kwargs)
except:
print('%s 頁的 %s 方法報錯,重試第%d次' % (webpage, fun.__name__, i))
time.sleep(1)
else:
print('%s 頁的 %s 方法重復(fù)執(zhí)行3次失敗退出方法!' % (webpage, fun.__name__))
return wrapper
return function
class User():
def __init__(self, user, pwd):
self.user = user
self.pwd = pwd
@three_loop('登陸')
def huancun(self):
page = rpa.chrome.create('chrome://settings/')
rpa.chrome.max_window()
if rpa.win32.element_count("恢復(fù)彈窗"):
rpa.win32.click("恢復(fù)彈窗")
rpa.win32.click("清除緩存1")
time.sleep(1)
rpa.win32.click("清除緩存2")