Appium中wait_activity的使用以及XPATH定位
1 # -*- coding:utf-8 -*- 2 from appium import webdriver 3 from time import sleep 4 5 desired_caps ={ 6 'platformName':'Android', 7 'deviceName':'127.0.0.1:62001', 8 'platformVersion':'4.4.2', 9 'appPackage':'com.baidu.yuedu', 10 'appActivity':'com.baidu.yuedu.splash.SplashActivity', 11 'unicodeKeyboard':True,#绕过手机键盘操作,unicodeKeyboard是使用unicode编码方式发送字符串 12 'resetKeyboard':True,#绕过手机键盘操作,resetKeyboard是将键盘隐藏起来 13 'automationName':'UIautomator2', 14 # 'appPackage':'com.android.browser', 15 # 'appActivity':'com.android.browser.BrowserActivity' 16 # 'appPackage':'com.hsd.huosuda_user', 17 # 'appActivity':'com.hsd.huosuda_user.guide.WelcomeActivity' 18 } 19 driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub',desired_caps) 20 sleep(10) 21 cur_activity = driver.current_activity#获取当前Activity 22 print(cur_activity)#输出.base.ui.MainActivity 23 driver.wait_activity('.base.ui.MainActivity',60)#等待60秒,直到获取Activity跳过,默认每一秒获取一次 24 sleep(3) 25 driver.tap([(556,656),(631,704)],500)#模拟手势点击 26 sleep(5) 27 driver.tap([(141,791),(348,851)],500)#模拟手势点击 28 sleep(5) 29 # driver.find_element_by_xpath("//android.widget.TextView[@text='图书']").click()#如果有多个图书,获取指定类的text 30 driver.find_element_by_xpath("//*[@text='小说']").click() 31 sleep(5) 32 driver.tap([(637,65),(691,94)],500)#模拟手势点击 33 34 # print(driver.contexts)获取当前上下文环境是原生还是H5