App自动化之xpath定位-----初级篇(5)
作者:互联网
一、先做好与各个设备的连接: appium与模拟器
二、appium中写好参数(要测试的apk),启动会话
三、通过xpath定位,进入【我的】模块下
复制xpath路径
from appium import webdriver
from appium.webdriver.common.touch_action import TouchAction
import time
dic = {
"platformVersion":"5.1.1", # 连接模拟器的系统版本
"platformName":"Android", # 连接模拟器的系统
"deviceName":"127.0.0.1:62001", # 你所连接的设备名
"appPackage":"com.jhss.youguu", # 要测试的apk包名
"appActivity":".SplashActivity" # 要测试apk的activity时间
}
driver = webdriver.Remote("http://localhost:4723/wd/hub",dic)
time.sleep(5)
TouchAction(driver).press(x = 837,y=760).move_to(x=56,y=868).release().perform()
time.sleep(5)
TouchAction(driver).press(x = 837,y=760).move_to(x=56,y=868).release().perform()
time.sleep(5)
TouchAction(driver).press(x = 837,y=760).move_to(x=56,y=868).release().perform()
time.sleep(5)
TouchAction(driver).tap(x=462,y=1457).perform()
# 点击关闭广告,使用强制等待,等待广告的出现,再关闭
time.sleep(5)
TouchAction(driver).tap(x = 679,y = 592).perform()
#通过id点击,进入【我的】模块下
# driver.find_element_by_id('com.jhss.youguu:id/btn_desktop_discovery').click()
# 通过xpath点击定位,进入【我的】模块下
driver.find_element_by_xpath('/hierarchy/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout'
'/android.widget.LinearLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.RelativeLayout/'
'android.widget.LinearLayout/android.widget.TextView[1]').click()
但实际上这样的xpath路径太长了,可以根据text文本值,来进行xpath定位
driver.find_element_by_xpath('//*[@text="发现"]').click()
标签:xpath,widget,TouchAction,App,driver,初级,time,android 来源: https://blog.csdn.net/weixin_46457203/article/details/106255114