本文是基于python语言在android上实操的,仅记录(忽略排版~~~)

会不时更新的:

 from appium import webdriver
from selenium.webdriver.common.touch_actions import TouchActions #导入TouchActions类
import time caps = {}
caps["platformName"] = "Android"
caps["platformVersion"] = "8.0.0"
caps["deviceName"] = "Phone"
caps["appPackage"] = "com.android.settings"
caps["appActivity"] = ".Settings" driver = webdriver.Remote("http://localhost:4723/wd/hub", caps) time.sleep(1)
driver.find_element_by_xpath("//android.widget.TextView[@text='Network & Internet']").click()
print(driver.available_ime_engines) #返回安卓设备可用的输入法
driver.open_notifications() #打系统通知栏
time.sleep(2)
driver.press_keycode(4) #点击返回键关闭通知栏
driver.save_screenshot("new.png") #截取当前屏幕并命名new.png,然后保存到电脑脚本当前目录 '''driver.find_element_by_xpath("//android.widget.TextView[@text='Display']").click() #使用xpath方法定位
m = driver.find_element_by_xpath("//android.widget.TextView[@text='Adaptive brightness']")
print(m.get_attribute("className")) #获取元素m的className值 '''
'''
e = driver.find_element_by_android_uiautomator('new UiSelector().className("android.widget.SeekBar")') #使用uiautomator搭配class属性方法定位 控制条
ex = e.location.get('x') #获取元素初始横坐标
ey = e.location.get('y') #获取元素初始纵坐标
#driver.tap([(ex,ey)],500) #用tap方法点击拖动按钮的最左侧起始位置
#driver.tap([(ex+400,ey)],500) #用tap方法横向点击某按钮,ex+400,ey不变
driver.swipe(ex,ey,ex+400,ey,500) #用swipe方法横向拖动某按钮, ey纵坐标不变
time.sleep(1)
driver.press_keycode(4) #按导航返回键''' #driver.find_element_by_xpath("//android.widget.TextView[@text='Network & Internet']") '''k = driver.find_element_by_xpath("//android.widget.TextView[@text='Network & Internet']") #定位元素Network & Internet,通过xpath方式
kx = k.location.get('x') #获取元素的x坐标
ky = k.location.get('y') #获取元素的y坐标
driver.tap([(kx,ky)],5000) #长按元素坐标5s
time.sleep(2)
driver.install_app('F:\\soft\\weixin.apk') #安装app,后接apk路径
#driver.remove_app("com.tencent.mm") #删除app(包名)
driver.press_keycode('4') #按返回键
#driver.keyevent('3') #按home键
time.sleep(2)''' '''
driver.find_element_by_accessibility_id("Search settings").click() #定位并点击click()
#driver.find_element_by_id("android:id/search_src_text").send_keys('wifi') #定位到搜索输入栏,用.send_keys()方法模拟输入文本
#driver.find_element_by_id("android:id/search_src_text") #定位到搜索输入栏
driver.press_keycode(42) #模拟点击键盘上的n
driver.press_keycode(34) #模拟点击键盘上的f
driver.press_keycode(31) #模拟点击键盘上的c
time.sleep(1)
driver.find_element_by_accessibility_id("Clear query").click() #清除文本,用.clear()方法来清除输入文本 通过id方式定位
driver.find_element_by_accessibility_id("Navigate up").click() #点击返回键'''
'''
k = driver.find_element_by_xpath("//android.widget.TextView[@text='Network & Internet']") #定位元素并附值给k
print(k.size) #获取K元素的size,包括height, width
print(driver.get_window_size()) #打印屏幕分辨率
'''
'''time.sleep(2) #强制等待2s
x = driver.get_window_size()['width'] #获取屏幕的宽度
y = driver.get_window_size()['height'] #获取屏幕的高度
driver.swipe(1/2*x, 5/7*y, 1/2*x, 2/7*y, 1000) #从下往上滑动屏幕(5/7->2/7) time.sleep(2) driver.close_app() #关闭app
time.sleep(2)
driver.launch_app() #启动app
time.sleep(2)
driver.get_screenshot_as_file('G:\\Kemi\\pic.png') #截取当前屏幕并命名pic.png,然后保存到电脑G:\Kemi下
driver.save_screenshot("newContact.png") #截取当前屏幕并命名pic.png,然后保存到电脑当前目录下''' time.sleep(2) #driver.is_app_installed("com.android.settings") #检查app是否安装
#driver.find_element_by_xpath("//android.widget.TextView[@text='Brightness level']").is_displayed() # 定位元素并判断是否显示
#driver.find_element_by_xpath("//android.widget.TextView[@text='Brightness level']").is_enabled() #判断是否可用 #self.driver.find_element_by_android_uiautomator('new UiSelector().text("Long")').click() #使用uiautomator搭配text属性方法定位 弹框选项 x = driver.get_window_size()['width']
y = driver.get_window_size()['height']
driver.swipe(1/2*x, 6/7*y, 1/2*x, 1/7*y, 1000) #从下往上滑动屏幕
time.sleep(1)
driver.find_element_by_xpath("//android.widget.TextView[@text='Support']").click()
try: #使用try-except判断是否有弹窗,没有就pass跳过势将执行后面的操作
driver.find_element_by_id("com.sonymobile.support:id/eula_agree").click()
except Exception as e:
pass
try:
driver.find_element_by_id("com.android.packageinstaller:id/permission_allow_button").click()
except Exception as e:
pass
driver.find_element_by_xpath("//android.widget.ImageView[@resource-id='com.sonymobile.support:id/icon'][@instance='4']").click() #使用xpath下class、resource-id、instance联合定位
#driver.find_element_by_xpath("//android.widget.ImageView[@instance='4']").click() #效果同上句,用xpath下class及instance联合定位

最新文章

  1. Android—基于GifView显示gif动态图片
  2. BroadcastReceiver详解
  3. sql server 行转列(转载)
  4. Python中带参装饰器理解
  5. 注解:【有连接表的】Hibernate单向1->1关联
  6. java中日历代码的实现
  7. iOS - File Archive/UnArchive 文件压缩/解压
  8. stdobj to array php
  9. 二分+叉积判断方向 poj 2318 2398
  10. (转)实战Memcached缓存系统(3)Memcached配置参数初解
  11. 关于auto和decltype
  12. 网易云课堂_程序设计入门-C语言_第六章:数组_2鞍点
  13. Python正则表达式,统计分析nginx访问日志
  14. SQL Data Discovery and Classification
  15. c++文件的读写
  16. CentOS 7.4上网速度慢,修改DNS!
  17. Linux关机&重启命令
  18. API gateway 之 kong 安装
  19. [转]为Kindeditor控件添加图片自动上传功能
  20. Oracle相关内容整理

热门文章

  1. 浏览器工作原理(三):js运行机制及Event Loop
  2. 导出ExcelDemo
  3. 显示本月日历demo
  4. Disconf实践指南:改造篇
  5. HTTP之Tcp/Ip协议的工作原理
  6. leetcode382
  7. TBluetoothLEDevice.UpdateOnReconnect
  8. Java使用 VelocityEngine模板引擎快速生成HTML等各种代码
  9. 用django框架开发一个B2C购物网站的基本流程和用到的知识点总结1
  10. Oracle中关于DateTime的一些描述