如何在appium(ios,real device)python中滚动半屏

时间:2017-02-01 09:40:21

标签: python ios appium

我有一个问题,我必须向上滚动日历,每天都有自己的元素(可以添加或删除),并找到前一个日期的元素。

我只需要 - 从这里滚动到某个特定元素(假设它没有重复)。

我尝试过 -

self.driver.execute_script("mobile: scroll", {"direction": "up"})

它可以工作,但有时它会滚动,元素会再次变得不可见

理想的方法是有一些从这里滚动到某个元素的方法 或者不是滚动整个屏幕,而只是滚动一半。

我尝试了以下内容:

self.driver.execute_script("mobile: scroll", {"direction": "up", 'element': el})

self.driver.execute_script("mobile: scrollTo", {"direction": "up", 'element': el.id})

但它不起作用。

  • 硒(3.0.1)
  • Appium(1.6.3)
  • Python 2.7

3 个答案:

答案 0 :(得分:0)

我找到了解决方案。也许对某人有帮助: 例如,在我的情况下它将是(可滚动只剩下屏幕的一部分) < self.driver.swipe(window_size ['width'] * 0.3,window_size ['height'] * 0.15,window_size ['width'] * 0.3,window_size ['height'] * 0.65)>

答案 1 :(得分:0)

使用它,它可以工作。睡个好觉后再满足您的需求。

action = TouchAction(self.driver)
action.long_press(elementToTap).move_to(elementToDrag).release().perform()

答案 2 :(得分:0)

  1. 您应使用不带To的滚动
  2. 在同一词典中的“元素”旁边需要“ toVisible”
  3. 元素ID不是定位器ID,而是会话中的ID。可以使用getId()方法获取它

self.driver.execute_script("mobile: scroll", {"direction": "up", 'element': el.id, 'toVisible' : 'any non empty text'})

这应该与您合作