请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

报错:AttributeError: 'NoneType' object has no attribute 'split'

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] 中就不会报错,正常执行

请老师看下什么情况

正在回答 回答被采纳积分+3

1回答

Mushishi 2019-05-06 21:10:53

没有找到str,section=section,这里和你外面赋值顺序不对,外面赋值的是gologin,这个node不对吧

0 回复 有任何疑惑可以回复我~
  • 提问者 慕先生809202 #1
    赋值顺序要改成(“gologin”,”account”)吗?不太明白
    回复 有任何疑惑可以回复我~ 2019-05-06 21:29:59
  • Mushishi 回复 提问者 慕先生809202 #2
    value = self.read_init.get_value("account", "go_login")
    这没错。我看错了。进入进去打印一下信息
    回复 有任何疑惑可以回复我~ 2019-05-07 22:37:37
问题已解决,确定采纳
还有疑问,暂不采纳
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号