xpath positioning of App automation

1. First make the connection with each device:  appium and simulator

2. Write the parameters (apk to be tested) in appium and start the session

3. Through xpath positioning, enter the [My] module

copy xpath path

 

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()

But in fact, such an xpath path is too long, and xpath positioning can be performed according to the text text value

insert image description here

driver.find_element_by_xpath('//*[@text="发现"]').click()

 

Guess you like

Origin blog.csdn.net/suixing6/article/details/127079207