当前位置:网站首页>Appium automated test scroll and drag_ and_ Drop slides according to element position
Appium automated test scroll and drag_ and_ Drop slides according to element position
2022-07-06 17:49:00 【Test Road King】
background
We are operating APP When applied , Some need to slide from one element to another , At this time, we cannot determine the coordinates , therefore swipe According to the coordinate sliding mode, it cannot be used , Here's the picture : from Live class Slide up to Live open class Location 
At this time, we need to use other sliding methods , We thought we could slide according to the elements ,Appium The main methods of sliding according to elements are scroll and drag_and_drop
scroll Introduce
explain
Scroll from one element to another , It can only be the sliding between two elements .
Method details
def scroll(self: T, origin_el: WebElement, destination_el: WebElement, duration: Optional[int] = None) -> T:
"""Scrolls from one element to another Args: origin_el: the element from which to being scrolling destination_el: the element to scroll to duration: a duration after pressing originalEl and move the element to destinationEl. Default is 600 ms for W3C spec. Zero for MJSONWP. Usage: driver.scroll(el1, el2) Returns: Union['WebDriver', 'ActionHelpers']: Self instance """
# XCUITest x W3C spec has no duration by default in server side
if self.w3c and duration is None:
duration = 600
action = TouchAction(self)
if duration is None:
action.press(origin_el).move_to(destination_el).release().perform()
else:
action.press(origin_el).wait(duration).move_to(destination_el).release().perform()
return self
Parameters :
- origin_el - Start element to scroll
- destination_el - End element to scroll to
- duration - The duration of the , Unit millisecond , The default is 600 ms
Operation scenario
- Enter Netease cloud homepage
- Slide from live classroom broadcast to live open class
Key code implementation
# Locate the classroom live broadcast element
el1 = driver.find_element(AppiumBy.XPATH, "//*[@text=' Live class ']").click()
# Locate the live open class element
el2 = driver.find_element(AppiumBy.XPATH, "//*[@text=' Live open class ']").click()
# Of board ⾏ Sliding operation
driver.scroll(el1,el2)
explain
- The operation process includes inertia , Need to add duration Parameters , The larger the parameter value is , The smaller the inertia .
drag_and_drop Introduce
explain
Slide from one element to another , The second element replaces the original screen position of the first element .
Method details
def drag_and_drop(self: T, origin_el: WebElement, destination_el: WebElement) -> T:
"""Drag the origin element to the destination element Args: origin_el: the element to drag destination_el: the element to drag to Returns: Union['WebDriver', 'ActionHelpers']: Self instance """
action = TouchAction(self)
action.long_press(origin_el).move_to(destination_el).release().perform()
return self
Parameters :
- origin_el - To slide the starting element of the page
- destination_el - To slide the page to the end element
Operation scenario
- Enter Netease cloud homepage
- Slide from live classroom broadcast to live open class
Key code implementation
# Locate the classroom live broadcast element
el1 = driver.find_element(AppiumBy.XPATH, "//*[@text=' Live class ']").click()
# Locate the live open class element
el2 = driver.find_element(AppiumBy.XPATH, "//*[@text=' Live open class ']").click()
# Of board ⾏ Sliding operation
driver.drag_and_drop(el1,el2)
explain
- Cannot set duration , No inertia
Slide and drag usage scene selection
Sliding and dragging are nothing more than considering whether it has “ inertia ”, And the parameters passed are “ Elements ” still “ coordinate ”.
- scroll: Yes “ inertia ” , Pass in “ Elements ”, Can be set by duration Parameters to control the inertia
- drag_and_drop: nothing “ inertia ” , Pass in “ Elements ”
- swipe: Yes “ inertia ” , Pass in “ coordinate ”, Can be set by duration Parameters to control the inertia
explain : add to duration Parameters , The larger the parameter value is , The smaller the inertia
The above content is purely personal understanding , If there is any deficiency , Welcome to correct !
If you think the article is good , Welcome to WeChat official account. , The official account of WeChat is regularly pushing the relevant test technology articles.
边栏推荐
- Flet教程之 13 ListView最常用的滚动控件 基础入门(教程含源码)
- Xin'an Second Edition: Chapter 24 industrial control safety demand analysis and safety protection engineering learning notes
- Cool Lehman has a variety of AI digital human images to create a vr virtual exhibition hall with a sense of technology
- Guidelines for preparing for the 2022 soft exam information security engineer exam
- Interpretation of Flink source code (II): Interpretation of jobgraph source code
- Awk command exercise
- It doesn't make sense without a distributed gateway
- Openharmony developer documentation open source project
- Summary of study notes for 2022 soft exam information security engineer preparation
- TCP连接不止用TCP协议沟通
猜你喜欢

EasyCVR电子地图中设备播放器loading样式的居中对齐优化

There is a gap in traditional home decoration. VR panoramic home decoration allows you to experience the completion effect of your new house

78 岁华科教授逐梦 40 载,国产数据库达梦冲刺 IPO

Development and practice of lightweight planning service tools

Pyspark operator processing spatial data full parsing (4): let's talk about spatial operations first

【MySQL入门】第三话 · MySQL中常见的数据类型

Grafana 9 正式发布,更易用,更酷炫了!

Sqoop I have everything you want

网络分层概念及基本知识

中移动、蚂蚁、顺丰、兴盛优选技术专家,带你了解架构稳定性保障
随机推荐
Based on infragistics Document. Excel export table class
sql语句优化,order by desc速度优化
2022年大厂Android面试题汇总(一)(含答案)
分布式不来点网关都说不过去
Flink parsing (V): state and state backend
EasyCVR授权到期页面无法登录,该如何解决?
There is a gap in traditional home decoration. VR panoramic home decoration allows you to experience the completion effect of your new house
【Elastic】Elastic缺少xpack无法创建模板 unknown setting index.lifecycle.name index.lifecycle.rollover_alias
Summary of study notes for 2022 soft exam information security engineer preparation
Nodejs 开发者路线图 2022 零基础学习指南
Flink parsing (VII): time window
scratch疫情隔离和核酸检测模拟 电子学会图形化编程scratch等级考试三级真题和答案解析2022年6月
Establishment of graphical monitoring grafana
Flink analysis (II): analysis of backpressure mechanism
Error: Publish of Process project to Orchestrator failed. The operation has timed out.
Huawei certified cloud computing hica
About selenium starting Chrome browser flash back
Hongmeng introduction and development environment construction
Interpretation of Flink source code (I): Interpretation of streamgraph source code
SAP UI5 框架的 manifest.json
