需要导入方法NoSuchElementException
1 from appium import webdriver 2 from selenium.common.exceptions import NoSuchElementException 3 import time 4 desired_caps = { 5 #android的apk 6 'platformName': 'Android', 7 #手机设备名称 8 'deviceName': '192.168.175.101:5555', 9 #android系统的版本号 10 'platformVersion': '4.4.4', 11 # 'deviceName': 'ceshi', 12 # 'platformVersion': '7.0', 13 # 'udid':'83f04b4b5338424e', 14 15 16 'app':r'C:UserszARTDesktopapp-artmall-release.apk', 17 # apk包名 18 'appPackage': 'com.baozhenart.artmall', 19 # apk的launcherActivity 20 'appActivity': 'com.baozhenart.artmall.SplashActivity', 21 #默认neReset为false,不要在会话前重置应用状态,每次启动都跟第一次启动一样,变为true则不一样 22 'noReset':'True', 23 #下面两行代码是为了屏蔽软件盘以至于可以输入中文 24 'unicodeKeyboard':True,#使用unicode编码方式发送字符串 25 'resetKeyboard':True#将键盘隐藏起来 26 } 27 driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps) 28 #检测跳过按钮 29 def check_skipBtn(): 30 print('check skipBtn') 31 try: 32 skipBtn=driver.find_element_by_id("com.baozhenart.artmall:id/tv_skip") 33 except NoSuchElementException: 34 print('no skipBtn') 35 else: 36 skipBtn.click() 37 time.sleep(5) 38 #检测是否有叉号 39 def check_closeBtn(): 40 print('check closeBtn') 41 try: 42 closeBtn=driver.find_element_by_id("com.baozhenart.artmall:id/iv_close") 43 except NoSuchElementException: 44 print('no closeBtn') 45 else: 46 closeBtn.click() 47 check_skipBtn() 48 check_closeBtn()