Issue with scrollTo and scrollToExact methods of A

2019-08-31 11:45发布

问题:

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.

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 version: 1.2.3
Java client version: 2.1.0

回答1:

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);