你好老师,执行下面的run_main(),代码执行到opera_method下的on_click()函数时报错’str’ object has no attribute ‘get_by_local’,不知道如何解决
run_main.py:
# coding = utf-8
from keywords.opera_method import OperaMethod
from keywords.get_data import GetData
from util.server import Server
class RunMain:
def run_method(self):
appium_server = Server()
appium_server.main()
self.opera_method = OperaMethod()
self.get_data = GetData()
lines = self.get_data.get_case_lines()
for i in range(1,lines):
handle_step = self.get_data.get_handle_step(i) # 操作步骤
element_key = self.get_data.get_handle_element(i) #操作元素key
print(type(element_key))
print(element_key)
handle_value = self.get_data.get_handle_value(i) # 操作值
expect_element = self.get_data.get_expect_element(i) # 预期结果元素
expect_step = self.get_data.get_expect_step(i) #获取预期步骤
excute_method = getattr(OperaMethod,handle_step)
if handle_value != None:
excute_method(element_key,handle_value) # input操作
else:
excute_method(element_key)
if expect_step != None:
expect_result = getattr(OperaMethod,expect_step)
expect_result(expect_element)
if __name__ == '__main__':
run_main = RunMain()
run_main.run_method()
opera_method.py:
# coding = utf-8
from util.get_by_local import getByLocal
from base.base_driver import BaseDriver
import time
class OperaMethod:
def __init__(self):
base_driver = BaseDriver()
self.driver = base_driver.android_driver(0)
self.get_by_local = getByLocal(self.driver)
def input(self, *args):
'''
输入值
:param element_key: 元素(key值)
:param value:操作值
:return:
'''
element = self.get_by_local.get_element(args[0])
if element == None:
return args[0], '元素没有找到'
element.send_keys(args[1])
def on_click(self,*args):
'''
元素点击
'''
time.sleep(3)
element = self.get_by_local.get_element(args[0])
if element == None:
return args[0], '元素没有找到'
time.sleep(5)
element.click()
def sleep_time(self, *args):
time.sleep(args[0])
报错如下:
case.xlsx:
get_by_local.py:
# coding=utf-8
from util.read_init import readIni
class getByLocal:
def __init__(self, driver):
self.driver = driver
def get_element(self,key,section=None):
rI = readIni()
value = rI.get_value(key)
by = value.split('>')[0]
local_by = value.split('>')[1]
if value != None:
if by == 'id':
return self.driver.find_element_by_id(local_by)
elif by == 'class_name':
return self.driver.find_element_by_class_name(local_by)
elif by == 'android_uiautomator':
return self.driver.find_element_by_android_uiautomator(local_by)
else:
return self.driver.find_element_by_xpath(local_by)
else:
return None