使用Appium-Python在Android应用中进行垂直滚动 [英] Vertical scrolling in Android app using Appium-Python

查看:77
本文介绍了使用Appium-Python在Android应用中进行垂直滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是Android应用程序的UI.在此,朋友"列表的UI可见.它的总数为26个朋友.我想滚动用户界面,并希望看到所有的朋友. 我想通过Python-Appium做到这一点.我无法滚动它.怎么做?它具有资源ID,类名,程序包名,而我具有界限值,即[0,161] [540,887].

Following is the UI for android app. In this a UI of Friends list is visible. It have total number of 26 friends. I want to scroll the UI and want to see all the friends. I want to do this by Python-Appium. I am not able to scroll it. How to do it? It have resource-id, class name, package name and i have bounds values and that is [0,161][540,887].

推荐答案

我遇到了同样的问题.建议的大多数解决方案均无效.无论如何,我找到了您可以在下面看到的解决方案:

I had same problem. Most of the suggested solutions didn't work. Anyways, I found a solution you can see below:

    # import touch events
    from appium.webdriver.common.touch_action import TouchAction

    # Find the list element. 
    list = driver.find_element_by_id('com.abc.android.abc:id/common_tab_list')
    # define touch
    action = TouchAction(driver)

    # adjust here to your needs !
    for x in range(0,10):
       action.press(x=750,y=1750).move_to(x=0, y=-75).perform()

主要部分是for循环.基本上垂直滚动10次.您可能需要指定不同的x和y坐标.当您在设备上启用指针位置"时,您可以轻松找到答案.当您触摸屏幕时,这将显示x和y坐标.要启用它,只需转到

the main part is the for loop. Basically its scrolling vertically 10 times. You may need to give different x and y coordinates. You can easily find this out when you enable "pointer location" on your device. This will show x and y coordinates when you touch your screen. To enable it simply go to

  1. 设置
  2. 开发者选项
  3. 指针位置(名称可能有所不同,我的手机上有德语)

然后触摸设备底部和顶部,您将看到坐标.您可以将其添加到"action.press(x = yourX,y = yourY)...".

Then touch on the bottom of your device and on top you will see the coordinates. This you can add to "action.press(x=yourX, y=yourY)...."

move_to()-因为您希望垂直滚动将x保持原样. y为负数.负数表示我们实际上是在向上滚动而不是向下滚动.

move_to() - since you want vertical scroll leave x as it is. y has a negative. Negative means that we are actually scrolling up not down.

perfrom()被执行.没什么好说的.

perfrom() is perform. Not much to say.

现在我想再添加1件东西.您可以执行以下操作来代替for循环:

Now I want to add 1 more thing. Instead of a for loop you can do the following:

 action.press(x=750,y=1750).move_to(x=0, y=-200).release().perform()

注意到差异了吗?它是release().当您添加时,我发现列表将平滑滚动.就像您向上滑动时,列表具有一定的惯性一样.

Noticed the difference? It's release(). When you add this I found that the list will be scrolled smoothly. Like when you swipe up and the list has some inertia.

我不是专家,但我的回答至少应该对您有帮助. 祝你好运

Im not an expert but my answer should help you at least. Good luck

这篇关于使用Appium-Python在Android应用中进行垂直滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆