一、动作事件
ele = driver. find_element_by_id( 'ccn.xiaochuankeji.tieba:id/title' )
ele. click( )
ele. sendkeys( )
ele. clear( )
二、属性获取
height = driver. get_window_size( ) [ 'height' ]
width = driver. get_window_size( ) [ 'width' ]
print ( '该手机的屏幕分辨率为:{}*{}' . format ( height, width) )
ele = driver. find_element_by_id( 'ccn.xiaochuankeji.tieba:id/title' )
text = ele. text
activity = driver. current_activity
attibute = ele. get_attribute( 'className' )
ele. is_enabled( )
ele. is_displayed( )
三、swipe事件
'''
# 页面滑动
driver.swipe(startX,startY,endX,endY,time)
在持续时间内,完成起始坐标--终止坐标的移动操作
'''
driver. swipe( 500 , 200 , 500 , 200 , 100 )
driver. swipe( 500 , 1000 , 500 , 200 , 100 )
driver. swipe( 500 , 1000 , 500 , 200 , 3000 )
'''
适应于各个分辨率手机的swipe操作事件
'''
height = driver. get_window_size( ) [ 'height' ]
width = driver. get_window_size( ) [ 'width' ]
driver. swipe( width* 0.5 , height* 0.8 , width* 0.5 , height* 0.5 )
四、TouchAction类详解
from appium. webdriver. common. touch_action import TouchAction
ele = driver. find_element_by_id( 'ccn.xiaochuankeji.tieba:id/title' )
TouchAction( driver) . tap( ele) . perform( )
TouchAction( driver) . tap( x= 200 , y= 500 ) . perform( )
TouchAction( driver) . press( x= 500 , y= 300 ) . release( ) . perform( )
TouchAction( driver) . long_press( x= 500 , y= 300 , duration= 3000 ) . release( ) . perform( )
五、keyevent手机按键事件
'''
五、keyevent手机按键事件
参考博客:https://blog.csdn.net/midux/article/details/80064054
常用手机按键编号:
返回键:4
搜索键:84
回车键:66
退格键:67
'''
driver. keyevent( 4 )
driver. keyevent( 66 )
六、屏幕截图
driver. get_screenshot_as_file( "E:/new_file/app.png" )
七、输入框输入中文【需切换appium输入法】
desired_caps[ 'unicodeKeyboard' ] = 'True'
desired_caps[ 'resetKeyboard' ] = 'True'
八、每次执行代码后卸载重装APP
'''
使用此项需定义PATH
'''
PATH = lambda p: os. path. abspath( os. path. join( os. path. dirname( __file__) , p) )
desired_caps[ 'fullReset' ] = True
desired_caps[ 'app' ] = PATH( 'E:/newapp/app.apk' )
九、toast事件
import time
from selenium. webdriver. support. ui import WebDriverWait
from selenium. webdriver. common. by import By
from selenium. webdriver. support import expected_conditions as EC
desired_caps[ 'automationName' ] = 'Uiautomator2'
ele = WebDriverWait( driver, 10 , 0.5 ) . until_not(
EC. presence_of_element_located( ( 'xpath' , '//*contains(@text,"登陆成功")' ) ) )
print ( ele. text)