当前位置:网站首页>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.
边栏推荐
- Distinguish between basic disk and dynamic disk RAID disk redundant array
- FlutterWeb瀏覽器刷新後無法回退的解决方案
- Start job: operation returned an invalid status code 'badrequst' or 'forbidden‘
- Zen integration nails, bugs, needs, etc. are reminded by nails
- Growth of operation and maintenance Xiaobai - week 7
- Guidelines for preparing for the 2022 soft exam information security engineer exam
- 分布式不来点网关都说不过去
- Compile and build, from the bottom to the top
- Debug xv6
- Wordcloud colormap color set and custom colors
猜你喜欢
BearPi-HM_ Nano development board "flower protector" case
当前系统缺少NTFS格式转换器(convert.exe)
[elastic] elastic lacks xpack and cannot create template unknown setting index lifecycle. name index. lifecycle. rollover_ alias
Manifest of SAP ui5 framework json
[getting started with MySQL] fourth, explore operators in MySQL with Kiko
yarn : 无法加载文件 D:\ProgramFiles\nodejs\yarn.ps1,因为在此系统上禁止运行脚本
It doesn't make sense without a distributed gateway
EasyCVR电子地图中设备播放器loading样式的居中对齐优化
Easy introduction to SQL (1): addition, deletion, modification and simple query
历史上的今天:Google 之母出生;同一天诞生的两位图灵奖先驱
随机推荐
Kali2021 installation and basic configuration
Flink parsing (VII): time window
Interview shock 62: what are the precautions for group by?
78 岁华科教授逐梦 40 载,国产数据库达梦冲刺 IPO
The art of Engineering (2): the transformation from general type to specific type needs to be tested for legitimacy
Alertmanager sends the alarm email and specifies it as the Alibaba mailbox of the company
Xin'an Second Edition: Chapter 24 industrial control safety demand analysis and safety protection engineering learning notes
[getting started with MySQL] fourth, explore operators in MySQL with Kiko
Sqoop I have everything you want
[rapid environment construction] openharmony 10 minute tutorial (cub pie)
Remote code execution penetration test - B module test
Basic configuration and use of spark
OliveTin能在网页上安全运行shell命令(上)
How to submit data through post
How to output special symbols in shell
Xin'an Second Edition; Chapter 11 learning notes on the principle and application of network physical isolation technology
Example of batch update statement combining update and inner join in SQL Server
Flink analysis (II): analysis of backpressure mechanism
远程代码执行渗透测试——B模块测试
Spark calculation operator and some small details in liunx