模擬手指輕點、長按、滑動屏幕(七)


from init_driver.Init_driver import init_driver
import time
from appium.webdriver.common.touch_action import TouchAction
from selenium.webdriver.support.wait import WebDriverWait

driver = init_driver()

# 通過元素定位,模擬手指輕敲屏幕
e1 = driver.find_element_by_xpath("//*[contains(@text, '更多')]")
TouchAction(driver).tap(el).perform()
# 通過坐標定位,模擬手指輕敲屏幕
e2 = driver.find_element_by_xpath("//*[contains(@text, '更多')]").location
TouchAction(driver).tap(x=e2.get("x"), y=e2.get("y")).perform()

# 通過元素定位,模擬手指按下屏幕和松開手指
e3 = driver.find_element_by_xpath("//*[contains(@text, '更多')]")
TouchAction(driver).press(e3).release().perform()
# 通過坐標定位,模擬手指輕敲屏幕
e2 = driver.find_element_by_xpath("//*[contains(@text, '更多')]").location
TouchAction(driver).press(x=e2.get("x"), y=e2.get("y")).release().perform()

# 模擬手指按下屏幕,等待一段時間,松開手指---第一種方法
#
e3 = driver.find_element_by_xpath("//*[contains(@text, '更多')]")
TouchAction(driver).press(e3).wait(10000).release().perform()
# 模擬手指按下屏幕,等待一段時間,松開手指---第二種方法,元素定位
e3 = driver.find_element_by_xpath("//*[contains(@text, '更多')]")
TouchAction(driver).long_press(el=e3, duration=10000).release().perform()
# 第二種方法,坐標定位
e3 = driver.find_element_by_xpath("//*[contains(@text, '更多')]").location
TouchAction(driver).long_press(x=e3.get("x"), y=e3.get("y"), duration=10000).release().perform()

# 使用顯示等待
def wait_element(xpt):
    wait_w = WebDriverWait(driver, 5, 0.5).until(lambda x: x.find_element_by_xpath(xpt))
    return wait_w
# 進入圖案頁面
el_s = wait_element("//*[contains(@text, '聲音和振動')]")
el_t = wait_element("//*[contains(@text, '飛行模式')]")
driver.drag_and_drop(el_s, el_t)
wait_element("//*[contains(@text, '密碼與安全')]").click()
wait_element("//*[contains(@text, '屏幕鎖定方式')]").click()
wait_element("//*[contains(@text, '圖案密碼')]").click()
# 繪制手勢, 坐標定位移動  1:285,836   2:539,836   3:539,1092   4:285,1089
TouchAction(driver).press(x=285, y=836).move_to(x=254, y=0).move_to(x=0, y=256)\
    .move_to(x=-254, y=0).release().perform()
# 元素定位移動
TouchAction(driver).press(el_t).move_to(el_s).release().perform()
# 坐標定位移動
TouchAction(driver).press(x=221, y=1660).move_to(x=0, y=-1015).release().perform()

time.sleep(5)
driver.quit()

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM