当前位置:网站首页>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.
边栏推荐
- Solr appears write Lock, solrexception: could not get leader props in the log
- VR全景婚礼,帮助新人记录浪漫且美好的场景
- C WinForm series button easy to use
- 开源与安全的“冰与火之歌”
- node の SQLite
- C version selenium operation chrome full screen mode display (F11)
- 远程代码执行渗透测试——B模块测试
- C# NanoFramework 点灯和按键 之 ESP32
- 在一台服务器上部署多个EasyCVR出现报错“Press any to exit”,如何解决?
- EasyCVR授权到期页面无法登录,该如何解决?
猜你喜欢
EasyCVR电子地图中设备播放器loading样式的居中对齐优化
Uipath browser performs actions in the new tab
EasyCVR平台通过接口编辑通道出现报错“ID不能为空”,是什么原因?
[elastic] elastic lacks xpack and cannot create template unknown setting index lifecycle. name index. lifecycle. rollover_ alias
After entering Alibaba for the interview and returning with a salary of 35K, I summarized an interview question of Alibaba test engineer
C# NanoFramework 点灯和按键 之 ESP32
Concept and basic knowledge of network layering
一体化实时 HTAP 数据库 StoneDB,如何替换 MySQL 并实现近百倍性能提升
Unity小技巧 - 绘制瞄准准心
It doesn't make sense without a distributed gateway
随机推荐
Openharmony developer documentation open source project
Binary search strategy
Solrcloud related commands
中移动、蚂蚁、顺丰、兴盛优选技术专家,带你了解架构稳定性保障
当前系统缺少NTFS格式转换器(convert.exe)
Development and practice of lightweight planning service tools
Unity particle special effects series - treasure chest of shining stars
Solution qui ne peut pas être retournée après la mise à jour du navigateur Web flutter
Pyspark operator processing spatial data full parsing (5): how to use spatial operation interface in pyspark
BearPi-HM_ Nano development environment
Basic configuration and use of spark
[introduction to MySQL] third, common data types in MySQL
Reppoints: advanced order of deformable convolution
Easy introduction to SQL (1): addition, deletion, modification and simple query
[elastic] elastic lacks xpack and cannot create template unknown setting index lifecycle. name index. lifecycle. rollover_ alias
Debug xv6
Xin'an Second Edition; Chapter 11 learning notes on the principle and application of network physical isolation technology
PySpark算子处理空间数据全解析(5): 如何在PySpark里面使用空间运算接口
The solution to the left-right sliding conflict caused by nesting Baidu MapView in the fragment of viewpager
[ASM] introduction and use of bytecode operation classwriter class