App automation ----- id positioning

1. Appium has been opened , and the emulator has been connected using the adb command

insert image description here

2. Appium writes all parameters and starts the session

 insert image description here

 

3. Get the id element value

Click the first button Select Elements in the first row in appium to get the positioning element

insert image description here

Click the [Discover] button here to copy the id element I marked in red

insert image description here

As long as the elements that appear in Find By in appium are unique elements, we don't need to verify them

4. Code implementation

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

Simulator effect:

insert image description here

 

Guess you like

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