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

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

问题描述

我们正在开发 Cordova 移动应用程序.在屏幕上,我们有一个表格格式的值列表.如果我们想选择一个不在移动设备可见范围内的元素,我们需要执行滚动操作.方法 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天全站免登陆