下面是代码:
AndroidDriver androidDriver;
public void scrollDown() {
androidDriver.getCapabilities().getCapability("hub");
androidDriver.manage().window().getSize();
Dimension size = androidDriver.manage().window().getSize();
int startX = size.width / 2;
int startY = (int) (size.height * 0.60);
int endY = (int) (size.height * 0.30);
new TouchAction(androidDriver).longPress(startX, startY).moveTo(startX, endY).release().perform();
}
我尝试添加一个waitAction,但仍然无法正常工作
new TouchAction(androidDriver).longPress(startX, startY).waitAction(Duration.ofSeconds(3)).moveTo(startX, endY).release().perform();
我什至尝试过刷卡,但不能刷卡:
// new TouchAction(androidDriver)
// .press(PointOption.point(startX, startY))
// .waitAction(WaitOptions.waitOptions(Duration.ofSeconds(3)))
// .moveTo(PointOption.point(startX, endY))
// .release().perform();
longPress中的startX和startY基本上是红色下划线,但是此代码之前确实起作用,但是现在我得到了红线。另一件事是我更改了Android驱动程序,以便它从“中心”中获得功能,该中心在Serenity属性中设置,例如(xxx out值):
webdriver.driver= appium
appium.hub = http://xxx.xxx.xxx.xxx:xxx/wd/hub
appium.automationName=appium
appium.platformName = Android
appium.app= ./xxxdebug.apk
appium.appPackage = xxx.debug
appium.appWaitActivity = xxx.StartupActivity
#appium.browserName =
serenity.take.screenshots= AFTER_EACH_STEP
webdriver.timeouts.implicitlywait = 10000
appium.fullReset=true
appium.noReset=false
logging = "VERBOSE"
答案 0 :(得分:1)
我相信您的问题在于您没有使用PointOption参数:
TouchAction touchAction = new TouchAction(driver);
touchAction.longPress(PointOption.point(startx, starty))
.moveTo(PointOption.point(endx, endy))
.release()
.perform();
答案 1 :(得分:0)
这是我在Kotlin中使用的:
fun setScrollViewToTop() {
android.os.Handler().postDelayed({
try {
activity!!.findViewById<ScrollView>(R.id.scrollViewActivity).fullScroll(ScrollView.FOCUS_UP)
} catch (t: Throwable) {
}
}, 125)
}