【问题标题】:How to scroll list once in android application using Appium and Python如何使用 Appium 和 Python 在 android 应用程序中滚动列表一次
【发布时间】:2016-08-28 04:29:44
【问题描述】:

我想使用 Python 滚动到 Android 应用程序中的列表,以下代码对我有用:

self.driver.find_element_by_android_uiautomator('new UiScrollable(newUiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().text("India").instance(0));')

但这会滚动列表,直到它不在印度,但我只想滚动一次。

我也试过这个:

el1 = self.driver.find_element_by_xpath("//*[@resource-id = 'resource-id' and @index ='1']")
el2 = self.driver.find_element_by_xpath("//*[@resource-id = 'resource-id' and @index ='0']")
self.driver.scroll(el1, el2)

这也滚动列表,但它正在做一个长滚动,但我想去列表中的每个元素。

谁能告诉我如何滚动列表一次?

【问题讨论】:

  • 不确定scrollIntoView(new UiSelector().text("India") 是如何工作的,但您能否尝试在列表中查找第二个元素的文本并执行与scrollIntoView(new UiSelector().text("<text of 2nd element>") 相同的操作
  • 我尝试了这个并且完美地为我工作,我只是使用了像按下和释放这样的触摸动作,因为我想滚动一次,所以从中删除 release() 部分然后它工作非常适合我 :) el1 = self.driver.find_element_by_xpath("") action = TouchAction(self.driver) action.press(el1).move_to(el2 ).perform() 还有谁想要一样的,他/她可以使用相同的基本原理。
  • 如果是这种情况,您可以自己分享它作为这个问题的答案。

标签: android python selenium appium vertical-scrolling


【解决方案1】:

我刚刚滚动,它很棒。当测试运行时,您只需要从下向上滑动即可。试试吧,它100%有效。

【讨论】:

    【解决方案2】:

    我尝试了下面提到的代码,并且非常适合我想要的。我只是使用了像按下和释放这样的触摸动作,因为我想滚动一次,所以从中删除 release() 部分,然后它对我来说非常有用:)

    el1 = self.driver.find_element_by_xpath("<xpath>")    
    el2 = self.driver.find_element_by_xpath("<xpath>")    
    action = TouchAction(self.driver)    
    action.press(el1).move_to(el2).perform()    
    

    还有谁想要相同的,他/她可以使用相同的基本原理。

    【讨论】:

      猜你喜欢
      • 2015-11-17
      • 2018-09-04
      • 2015-03-06
      • 2021-11-27
      • 1970-01-01
      • 1970-01-01
      • 2015-09-01
      • 1970-01-01
      • 2020-02-20
      相关资源
      最近更新 更多