场景:

  有的按钮在第一次打开时显示,之后就不显示了,如更新提示、特性介绍等,面对这样的场景写了如下脚本,增加脚本的复用性。

no_element_exception_2.py

 from appium import webdriver
from selenium.common.exceptions import NoSuchElementException desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['deviceName'] = '127.0.0.1:62001'
desired_caps['platforVersion'] = '5.1.1' # 真机配置
# desired_caps['deviceName']='MX4'
# desired_caps['platforVersion']='5.1'
# desired_caps['udid']='750BBKL22GDN' # desired_caps['app'] = r'C:\python_dir\apps\kaoyan3.1.0.apk'
desired_caps['appPackage'] = 'com.tal.kaoyan'
desired_caps['appActivity'] = 'com.tal.kaoyan.ui.activity.SplashActivity' # 重置开关,默认false,默认每次如第一次安装好的状态
desired_caps['noReset'] = 'True' driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
driver.implicitly_wait(5) def check_cancelBtn():
print("check cancel button")
try:
cancelBtn = driver.find_element_by_id('android:id/button2')
except NoSuchElementException:
print("no cancel button")
else:
cancelBtn.click()
driver.implicitly_wait(2) def check_skipBtn():
print("check skip button")
try:
skipBtn = driver.find_element_by_id('com.tal.kaoyan:id/tv_skip')
except NoSuchElementException:
print("no skip button")
else:
skipBtn.click()
driver.implicitly_wait(2) check_cancelBtn()
check_skipBtn()
driver.find_element_by_id('com.tal.kaoyan:id/login_register_text').click()
driver.implicitly_wait(5)

最新文章

  1. ABP框架 - 时间
  2. csharp: Importing or Exporting Data from Worksheets using aspose cell
  3. Elastic search入门
  4. python paramiko ssh.exec_command()启动tomcat服务器应用进程失败问题解决方法- Neither the JAVA_HOME nor the JRE_HOME environment variable is defined At least one of these environment variable is needed to run this progr
  5. shader学习路线
  6. Apache Struts 跨站脚本漏洞
  7. OMCS开发手册(01) -- 多媒体设备管理器
  8. patch 28729262
  9. LeetCode.数字转罗马数字
  10. (二分查找 拓展) leetcode278. First Bad Version
  11. Navicat premium 破解步骤
  12. webapi 统一处理时间格式
  13. 连接mysql数据库,创建用户模型
  14. Java之基础学习(数据类型、运算符、分支语句和循环语句)
  15. xml解析 使用dom4j操作xml
  16. 020 $.each的使用
  17. Error:..\FreeRTOS\portable\RVDS\ARM_CM3\port.c,378 Error:..\FreeRTOS\portable\RVDS\ARM_CM3\port.c,378 Error:..\FreeRTOS\portable\RVDS\ARM_CM3\port.c,378 Error:..\FreeRTOS\tasks.c,2806
  18. 冲刺Two之站立会议1
  19. Graham求凸包模板
  20. 如何解决“当前上下文中不存在名称“XXXXXXXX””的问题

热门文章

  1. go语言笔记1
  2. 个人第五次作业-alpha2测试
  3. POI IndexedColors 编码 与 颜色 对照
  4. Codeforces C. Elections(贪心枚举三分)
  5. C# 退出应用程序的几种方法
  6. JavaWeb报错:java.sql.SQLException: Invalid value for getInt()
  7. FTP服务FileZilla Server上传提示550 Permission denied
  8. docker容器配置加速器
  9. [VSCode] Adding Custom Syntax Highlighting to a Theme in VSCode
  10. 20199302《Linux内核原理与分析》第十二周作业