当前位置:网站首页>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.
边栏推荐
- Flink parsing (VII): time window
- Compile and build, from the bottom to the top
- EasyCVR电子地图中设备播放器loading样式的居中对齐优化
- How to use scroll bars to dynamically adjust parameters in opencv
- Openharmony developer documentation open source project
- Interpretation of Flink source code (II): Interpretation of jobgraph source code
- [introduction to MySQL] the first sentence · first time in the "database" Mainland
- VR panoramic wedding helps couples record romantic and beautiful scenes
- kivy教程之在 Kivy 中支持中文以构建跨平台应用程序(教程含源码)
- Remote code execution penetration test - B module test
猜你喜欢
Flink analysis (I): basic concept analysis
EasyCVR授权到期页面无法登录,该如何解决?
面试突击63:MySQL 中如何去重?
kivy教程之在 Kivy 中支持中文以构建跨平台应用程序(教程含源码)
Wordcloud colormap color set and custom colors
基本磁盘与动态磁盘 RAID磁盘冗余阵列区分
Solr appears write Lock, solrexception: could not get leader props in the log
The solution that flutterweb browser cannot be rolled back after refreshing
Flink parsing (IV): recovery mechanism
全网最全tcpdump和Wireshark抓包实践
随机推荐
面试突击62:group by 有哪些注意事项?
EasyCVR授权到期页面无法登录,该如何解决?
connection reset by peer
Cool Lehman has a variety of AI digital human images to create a vr virtual exhibition hall with a sense of technology
After entering Alibaba for the interview and returning with a salary of 35K, I summarized an interview question of Alibaba test engineer
Alibaba brand data bank: introduction to the most complete data bank
kivy教程之在 Kivy 中支持中文以构建跨平台应用程序(教程含源码)
Establishment of graphical monitoring grafana
Openharmony developer documentation open source project
Quick start of Hongmeng system
Flink parsing (IV): recovery mechanism
VR panoramic wedding helps couples record romantic and beautiful scenes
The solution that flutterweb browser cannot be rolled back after refreshing
酷雷曼多种AI数字人形象,打造科技感VR虚拟展厅
Remote code execution penetration test - B module test
Interview assault 63: how to remove duplication in MySQL?
VR全景婚礼,帮助新人记录浪漫且美好的场景
OliveTin能在网页上安全运行shell命令(上)
10 advanced concepts that must be understood in learning SQL
Spark accumulator and broadcast variables and beginners of sparksql