问题与Android驱动的scrollTo和scrollToExact方法。方法不滚动到所需的元素文本,但滚动到尾页 [英] Issue with scrollTo and scrollToExact methods of Android Driver. Methods do not scroll to required element text, but scroll to end of page

查看:1509
本文介绍了问题与Android驱动的scrollTo和scrollToExact方法。方法不滚动到所需的元素文本,但滚动到尾页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在研究一种科尔多瓦移动应用程序。上的画面,我们具有值的表中的格式的明细表。我们需要的,如果我们希望在可见光范围内的所述移动设备上不选择一个元素来执行滚动操作。该方法 scrollTo() scrollToExact()曾经尝试过,但这些不滚动到所需的元素文本,但超越它,这是在列表中最后的值。

We are working on a Cordova mobile application. On a screen we have a list of values in a table format. We need to perform a scroll action if we want to select an element not in visible range on the mobile device. The methods scrollTo() and scrollToExact() have been tried but these do not scroll to the required element text, but beyond it, that is to end of values in list.

移动到本机上下文执行滚动,有同样的结果。

Moving to native context for performing scroll, had same result.

此外,试图JavaScript方法 window.scrollTo() scrollintoView(),但滚动移动过去必需的元素

Also, tried Javascript methods window.scrollTo() and scrollintoView(), but scroll moves past required element.

是否有任何其他的方式来实现滚动必要元素的手机屏幕上,这样它不会滚动过去的必要元素?

Is there any other way to achieve scroll to necessary element on mobile screen, such that it does not scroll past the necessary element?

Appium版本:1.2.3结果
Java客户端版本:2.1.0

Appium version: 1.2.3
Java client version: 2.1.0

推荐答案

感谢您ShlomiTC的帮助,我能得到它首先检查工作,如果元素是可以在屏幕上,并用一个无限循环重复滚动屏幕,直到元件已被点击。如果元素没有被点击时,发生异常所以try / catch块帮我在这里。
希望这有助于具有类似问题的任何一个。

Thank you ShlomiTC for the help, I could get it working by first checking if element is available on screen and use an infinite loop to repeat scrolling the screen till the element has been clicked. If element is not clicked, an exception occurs so a try/catch block helped me here. Hope this helps any one having similar issue.

  js = (JavascriptExecutor) driver; 
  js.executeScript("window.scrollTo(0,0)"); 
  do 
  {
  try
  {
   driver.findElement(By.xpath(<xpathexpresssion>).click();
   break;
     }
  catch(Exception e)
  {
    js = (JavascriptExecutor) driver; 
    js.executeScript("window.scrollBy(0, 200)");

   }
 } while(true);

这篇关于问题与Android驱动的scrollTo和scrollToExact方法。方法不滚动到所需的元素文本,但滚动到尾页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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