报错:AttributeError: 'NoneType' object has no attribute 'split'
来源:2-2 读取配置文件代码封装实战

慕先生809202
2019-05-06
LocalElement.ini文件如下:
[login_Element]
username=id>cn.com.open.mooc:id/accountEdit
password=id>cn.com.open.mooc:id/passwordEdit
login_button=id>cn.com.open.mooc:id/login
forget_password=id>cn.com.open.mooc:id/forget_label
register=id>cn.com.open.mooc:id/right_text
version=id>cn.com.open.mooc:id/ivCancel
[go_login]
account=class_name>android.support.v7.app.ActionBar$Tab
login=id>cn.com.open.mooc:id/header_line
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):
read_ini=ReadIni()
local= read_ini.get_value(key)
by = local.split('>')[0]
local_by = local.split('>')[1]
# index = local.split('>')[2]
if by=='id':
return self.driver.find_element_by_id(local_by)
elif by=='class_name':
return self.driver.find_elements_by_class_name(local_by)
else:
return self.driver.find_element_by_xpath(local_by)
read_init.py脚本如下:
coding=utf-8
import ConfigParser
class ReadIni:
def __init__(self,file_path=None):
if file_path==None:
self.file_path='E:\Appium\config\LocalElement.ini'
else:
self.file_path=file_path
self.data=self.Read_ini()
def Read_ini(self):
read_ini = ConfigParser.ConfigParser()
read_ini.read(self.file_path)
return read_ini
def get_value(self,key,section=None):
if section==None:
section='login_Element'
else:
section=section
try:
value = self.data.get(section,key)
except:
value=None
return value
if name==‘main’:
aa = ReadIni()
print(aa.get_value(“account”, “go_login”))
login_page.py脚本如下:
def get_account_element(self):
value = self.read_init.get_value("account", "go_login")
return self.get_by_local.get_element(value)
login_handle.py 脚本:
def click_go_login(self,a):
elements = self.login_page.get_account_element()
elements[a].click()
login_bussiness.py脚本:
def go_login(self):
self.login_handle.click_go_login(3)
time.sleep(3)
self.login_handle.click_account_login()
执行test_case.py脚本报错:
ERROR: test_01 (main.CaseTest)
Traceback (most recent call last):
File “E:/Appium/case/test_case.py”, line 58, in test_01
self.login_bussiness.go_login()
File “E:\Appium\bussiness\login_bussiness.py”, line 11, in go_login
self.login_handle.click_go_login(3)
File “E:\Appium\handle\login_handle.py”, line 12, in click_go_login
elements = self.login_page.get_account_element()
File “E:\Appium\page\login_page.py”, line 25, in get_account_element
return self.get_by_local.get_element(value)
File “E:\Appium\util\get_by_local.py”, line 12, in get_element
by = local.split(’>’)[0]
AttributeError: ‘NoneType’ object has no attribute ‘split’
Ran 1 test in 22.976s
FAILED (errors=1)
Process finished with exit code 0
如果 把account的定位元素放在[login_Element] 中就不会报错,正常执行
请老师看下什么情况
1回答
-
Mushishi
2019-05-06
没有找到str,section=section,这里和你外面赋值顺序不对,外面赋值的是gologin,这个node不对吧
022019-05-07
相似问题