Last active
July 12, 2023 21:26
-
-
Save asolntsev/4693ce0768081880920557b78e6dce15 to your computer and use it in GitHub Desktop.
How to scroll in Appium
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Will be added to https://github.com/selenide/selenide-appium soon | |
// helper class | |
data class ScrollBy(val uiSelector: String) { | |
companion object { | |
fun toId(id: String) = ScrollBy("new UiSelector().resourceIdMatches(\".*id/$id\")") | |
fun toText(text: String) = ScrollBy("new UiSelector().text(\"${text}\")") | |
} | |
} | |
// helper method in BaseTest | |
protected fun scroll(selector: ScrollBy): WebElement { | |
val container = "new UiSelector().scrollable(true)" | |
val script = "new UiScrollable($container).scrollIntoView(${selector.uiSelector})" | |
return driver().findElement(MobileBy.AndroidUIAutomator(script)) | |
} | |
// usage | |
scroll(toId("account_balance")) | |
scroll(toText("Hello world")).click() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sure: just return nothing in method for iOS ><
BTW, for RecycleView component, this code should be little bit modified. So I created two methods:
scroll() and scrollRv().
For RV we need to use: