zoukankan      html  css  js  c++  java
  • 模拟手指轻点、长按、滑动屏幕(七)

    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()
  • 相关阅读:
    基于Debian的发行版Linux系统安装包命令
    戴尔服务器如何配置远程管理卡(IDRAC9)适用于戴尔R740服务器
    Tracert 命令
    Ubuntu 18.04 进入单用户模式修改密码
    华为eNSP模拟器— telnet实验
    华为交换机Console口属性配置
    Ubuntu 16.04 Bridge配置
    Ubuntu 16.04 配置单网卡绑定多IP
    springboot搭建web项目与使用配置文件
    读书笔记《SpringBoot编程思想》
  • 原文地址:https://www.cnblogs.com/zhaoquanmo/p/10751079.html
Copyright © 2011-2022 走看看