本文是基于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联合定位
05-08 15:26