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…
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:
scrollBy()
method to scroll a specific distance in pixels:This will scroll down by 250 pixels. You can use a negative value to scroll up.
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.