Query on the scroll functionality using Selenium with Appium

44 views
Skip to first unread message

arnab chanda

unread,
Dec 15, 2022, 2:28:04 AM12/15/22
to Selenium Users
Title: Not able to perform scroll in android application

 

Hi Guys,
Since Touch actions class is deprecated, and most other solutions using MobileBy.AndroidUIAutomator seems to be deprecated as well… Can you please provide me a solution on how to scroll in android application using java.

Code which I used where MobileBy.AndroidUIAutomator shows as depricated:

String text1 = “Register User (verify)”;
WebElement registerbtn = (WebElement) driver.findElement(
MobileBy.AndroidUIAutomator(“new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().”
+ “textContains(”"+text1+""))"));
registerbtn.click();

Touch actions which is also deprecated:

TouchActions action = new TouchActions(driver);
action.scroll(element, X, Y);
action.perform();

I have also tried using keyboards actions down it works fine, But it would be better If I get solutions or best practice to perform the scroll actions…

Vinayak S Kori

unread,
Dec 26, 2022, 6:20:37 AM12/26/22
to seleniu...@googlegroups.com
To scroll in an Android application using Java and Selenium, you can use the driver.executeScript() method to execute a JavaScript scroll command. Here is an example of how you can use this method to scroll to a specific element:

WebElement element = driver.findElement(By.id("element-id"));

JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].scrollIntoView();", element);


This will scroll the element with the ID "element-id" into view. You can also use the scrollBy() method to scroll a specific distance in pixels:

JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("window.scrollBy(0,250)", "");

This will scroll down by 250 pixels. You can use a negative value to scroll up.

Note that the MobileBy.AndroidUIAutomator() and TouchActions methods that you mentioned in your question are deprecated and should no longer be used. Instead, you should use the WebDriver and JavascriptExecutor methods as shown above. 
Reply all
Reply to author
Forward
0 new messages