gpt4 book ai didi

java - 如何在 java-client 7.0.0 中使用 appium 中的向下滑动/向下滚动?

转载 作者:行者123 更新时间:2023-12-02 10:06:28 25 4
gpt4 key购买 nike

这是我的代码,代码不起作用,控制台发送以下内容:java.lang.ClassCastException:无法将 com.sun.proxy.$Proxy18 转换为 org.openqa.selenium.remote.RemoteWebElement

我需要向下滑动/滚动。

TouchAction swipe = new TouchAction(ApplicationLauncherAndroid.driver)
.tap(element(lblImagen))// first initialElement
.waitAction(waitOptions(Duration.ofMillis(2000)))
.moveTo(element(elementoFinal)) final Element
.release();
swipe.perform();

最佳答案

在appium中使用以下方法进行滑动。确保您已从正确的库导入。

import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.MobileElement;
import org.openqa.selenium.Dimension;
import static io.appium.java_client.touch.WaitOptions;
import static io.appium.java_client.touch.offset.PointOption;
import static java.time.Duration.ofMillis;

//Vertical Swipe by percentages
public void verticalSwipeByPercentages(double startPercentage, double endPercentage, double anchorPercentage) {
Dimension size = driver.manage().window().getSize();
int anchor = (int) (size.width * anchorPercentage);
int startPoint = (int) (size.height * startPercentage);
int endPoint = (int) (size.height * endPercentage);

new TouchAction(driver)
.press(PointOption.point(anchor, startPoint))
.waitAction(WaitOptions.waitOptions(ofMillis(1000)))
.moveTo(PointOption.point(anchor, endPoint))
.release().perform();
}

//Swipe by elements
public void swipeByElements (MobileElement startElement, MobileElement endElement) {
int startX = startElement.getLocation().getX() + (startElement.getSize().getWidth() / 2);
int startY = startElement.getLocation().getY() + (startElement.getSize().getHeight() / 2);

int endX = endElement.getLocation().getX() + (endElement.getSize().getWidth() / 2);
int endY = endElement.getLocation().getY() + (endElement.getSize().getHeight() / 2);

new TouchAction(driver)
.press(PointOption.point(startX,startY))
.waitAction(WaitOptions.waitOptions(ofMillis(1000)))
.moveTo(PointOption.point(endX, endY))
.release().perform();
}

It seems like you are importing wrong TouchAction. Import touch action from io.appium.java_client.TouchAction

关于java - 如何在 java-client 7.0.0 中使用 appium 中的向下滑动/向下滚动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55307113/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com