我正在使用 Appium 进行移动自动化,并在我的测试脚本中实现了滚动机制。虽然滚动操作在我的 Android 模拟器上本地工作正常,但在 BrowserStack 上运行时无法正确执行。我使用以下方法进行滚动:
`
scrollToText 方法:
public void scrollToText(String text) {
driver.findElement(AppiumBy.androidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView(text(\"" + text + "\"))"));
}
向上滚动方法:
在此输入
public void scrollUp() {
boolean canScrollMore;
do {
canScrollMore = (Boolean) ((JavascriptExecutor) driver).executeScript("mobile: scrollGesture", ImmutableMap
.of("left", 100, "top", 100, "width", 200, "height", 200, "direction", "up", "percent", 3.0));
} while (canScrollMore);
}
scrollAndView method:
,,,,
public void scrollAndView(String visibleText) {
driver.findElement(AppiumBy.androidUIAutomator(
"new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().textContains(\"" + visibleText + "\").instance(0))"));
}
,,,,
The problem is that the scroll action works fine on my local setup but fails on BrowserStack. The elements are not scrolled to as expected, and I don't get any errors or exceptions.