报错AttributeError: 'str' object has no attribute 'send_keys'**

来源:6-9 关键字模型逻辑梳理之代码重构-2

慕数据2282311

2023-04-14

请老师帮忙看看
执行到 getlocal.get_element(‘username’).send_keys(‘13760276826’)时,报错:
File “D:/work/Auto/appiumScript/MicClientUIauto/moock/case/start_appium.py”, line 144, in NotFirst_login_Xpath
getlocal.get_element(‘username’).send_keys(‘13760276826’)
AttributeError: ‘str’ object has no attribute 'send_keys’

def startappium():
    '''
    启动appium
    :return:
    '''
    device=Devices.Check_adb_devices()
    capability = {
        "platformName": "Android",
        "deviceName": f"{device}",
        # "app": "D:\\learn\\muke_app\\imooc_8.3.3_10102001_android.apk",
        "appPackage":"cn.com.open.mooc",
        "appActivity":"com.imooc.component.imoocmain.splash.MCSplashActivity",
        "noReset":True
    }
    driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", capability)
    return driver

def NotFirst_login_Xpath():
    '''
    非首次登录
    Returns:
    '''
    getlocal=GetByLocals(driver)
    getlocal.get_element('mine').click()
    getlocal.get_element('clicklogin').click()
    getlocal.get_element('passwordlogin').click()
    getlocal.get_element('clearLoginData').click()
    getlocal.get_element('username').send_keys('13760276826')
from moock.util.readini import ReadIni
from appium.webdriver.common.mobileby import MobileBy
class GetByLocals:
    def __init__(self,driver):
        self.driver=driver
    def get_element(self,key):
        readinit=ReadIni()
        local=readinit.get_value(key)
        if local!=None:
            by=local.split('>')[0]
            byvalue=local.split('>')[1]
            if by=='id':
                return self.driver.find_element(MobileBy.ID,byvalue)
            elif by=='xpath':
                return self.driver.find_element(MobileBy.XPATH,byvalue)
            elif by=='ACCESSIBILITY_ID':
                return self.driver.find_element(MobileBy.ACCESSIBILITY_ID,byvalue)
            else:
                return self.driver.find_element(MobileBy.ANDROID_UIAUTOMATOR,byvalue)
        else:
            return '没有该元素'

写回答

2回答

Mushishi

2023-04-14

getlocal.get_element(‘username’)把你这个对象打出来,你看看 是一个str 不是element
0
1
慕数据2282311
好的,我写错了,usename写成了username
2023-04-14
共1条回复

慕数据2282311

提问者

2023-04-14

截图见下:

//img.mukewang.com/szimg/6438c7a909d1892a25391094.jpg

0
0

Python主讲移动端自动化测试框架Appium

APP自动化基础知识、po模型、关键字模型、服务自动化、持续集成

1508 学习 · 1333 问题

查看课程