# This sample code uses the Appium python client
# pip install Appium-Python-Client
# Then you can paste this into a file and simply run with Python
from appium import webdriver
import time
caps = {}
caps["platformName"] = "Android"
caps["deviceName"] = "127.0.0.1:62001"
caps["appPackage"] = "com.kmxs.reader"
caps["appActivity"] = "com.kmxs.reader.home.ui.HomeActivity"
driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)
el1 = driver.find_element_by_id("com.kmxs.reader:id/iv_update_close")
el1.click()
time.sleep(3)
el2 = driver.find_element_by_xpath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.View/androidx.viewpager.widget.ViewPager/android.widget.RelativeLayout/androidx.viewpager.widget.ViewPager/android.view.View/android.view.View/android.view.View[2]/android.widget.LinearLayout[2]/android.widget.TextView[1]")
el2.click()
time.sleep(2)
el3 = driver.find_element_by_id("com.kmxs.reader:id/book_detail_foot_free_read_tv")
el3.click()
time.sleep(10)
driver.tap([(864, 1342), (174, 1296)], 500)
driver.tap([(864, 1342), (174, 1296)], 500)*10
这个是 锁屏自动化
from appium import webdriver
# 导入WebDriverWait类
from appium.webdriver.common.touch_action import TouchAction
from selenium.webdriver.support.wait import WebDriverWait
import time
caps = {}
caps["platformName"] = "Android"
caps["deviceName"] = "127.0.0.1:62001"
caps["appPackage"] = "com.android.settings"
caps["appActivity"] = "com.android.settings.Settings"
driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)
TouchAction(driver).press(x=420, y=175).move_to(x=272, y=1195).release().perform()
TouchAction(driver).press(x=200, y=1184).move_to(x=434, y=181).release().perform()
el1 = driver.find_element_by_xpath("//*[contains(@text,'安全')]").click()
#el2 = driver.find_element_by_xpath("//*[contains(@text,'屏幕锁定方式')]").click()
time.sleep(5)
el2 = driver.find_element_by_xpath('/hierarchy/android.widget.FrameLayout/android.view.View/android.widget.FrameLayout[2]/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.ListView/android.widget.LinearLayout[1]/android.widget.RelativeLayout/android.widget.TextView[1]').click()
time.sleep(4)
TouchAction(driver).press(x=598,y=459).move_to(x=359,y=703).move_to(x=120,y=937).move_to(x=359,y=940).move_to(x=598,y=937).release().perform()