Python操作APP -- Appium-Python-Client

<a href='https://www.cnblogs.com/jiyu-hlzy/p/12228741.html' target='_blank'>Appium連接模擬器</a>

<br>

pip install Appium-Python-Client

<br>

使用Appium定位或者使用輔助定位工具

SDK安裝目錄/tools/bin,雙擊此輔助定位工具

<br><br>

from appium import webdriver

# 配置信息
desired = {
    "platformName": "Android",
    "platformVersion": "5.1.1",
    "deviceName": "127.0.0.1:62026",
    "appPackage": "com.android.settings",
    "appActivity": ".Settings"
}

# 固定路徑
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired)

# 獲取屏幕寬高
width, height = driver.get_window_size().values()

# 滾屏    耗時800ms
driver.swipe(width * 0.5, height * 0.8, width * 0.5, height * 0.3, 800)

# 定位元素
# ID
# element = driver.find_element_by_id('com.android.settings:id/title')
# xpath
ele_xpath = '/hierarchy/android.widget.FrameLayout/android.view.View/android.widget.FrameLayout[2]/android.widget.FrameLayout/android.widget.ScrollView/android.widget.LinearLayout/android.widget.LinearLayout[2]/android.view.View/android.widget.FrameLayout[5]/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.RelativeLayout/android.widget.TextView'
element = driver.find_element_by_xpath(ele_xpath)

# 獲取內容
print(element.get_attribute('text'))

# 點擊
element.click()

<br><br><br>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章