appium 用automator2定位toast提示,报错


# coding=utf-8

# toast提示必须安卓5.0以上


from appium import webdriver

from selenium.webdriver.support.ui import WebDriverWait

from selenium.webdriver.support import expected_conditions as EC


import time


def get_driver():


capabilities={

"platformName": "Android",

"automationName":"UiAutomator2",

"deviceName": "127.0.0.1:21503",

"app": "E:\\apptest\\appium_test\\apk\\imoc.apk",

# 注意这里的appActivity

"appWaitActivity":"com.imooc.component.imoocmain.splash.GuideActivity",

"noReset":"False"

}

driver=webdriver.Remote("http://127.0.0.1:4723/wd/hub",capabilities)

time.sleep(10)

return driver



def get_tost():

time.sleep(2)

# toast是不是需要时间等待

tost_element=("xpath","//*[contains(@text,'登录密码错误')]")

time.sleep(2)

print WebDriverWait(driver,10).until(EC.presence_of_element_located(tost_element))


driver = get_driver()




Traceback (most recent call last):

  File "E:\apptest\appium_test\testcase\case\toast_test.py", line 118, in <module>

    get_tost()

  File "E:\apptest\appium_test\testcase\case\toast_test.py", line 108, in get_tost

    print WebDriverWait(driver,10).until(EC.presence_of_element_located(tost_element))

  File "E:\cx\Python27\lib\site-packages\selenium-3.141.0-py2.7.egg\selenium\webdriver\support\wait.py", line 80, in until

    raise TimeoutException(message, screen, stacktrace)

selenium.common.exceptions.TimeoutException: Message: 


[Finished in 64.9s]


aimike
浏览 1812回答 2
2回答
打开App,查看更多内容
随时随地看视频慕课网APP