アプリ自動化の xpath の配置

1.まずappiumとシミュレータの各デバイスに接続します 

2. appiumにパラメータ(テスト対象のapk)を記述し、セッションを開始します

3. xpathの位置決めを通じて、[My] モジュールに入ります

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 パスは長すぎるため、xpath の位置決めはテキストのテキスト値に従って実行できます。

ここに画像の説明を挿入

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

 

おすすめ

転載: blog.csdn.net/suixing6/article/details/127079207