这是我的代码,不工作的代码和控制台发送如下: 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();
发布于 2019-03-23 08:42:51
在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();
}
似乎您导入了错误的TouchAction。从io.appium.java_client.TouchAction导入触摸操作
发布于 2019-03-23 12:49:27
@Pedro Perez Aballay,嗨。我建议使用以下备选方案:
(只适用于仪器化的应用程序-以及ListViews) --使用应用程序的内部API,类似于scrollIntoView在web上的工作方式,尽管它需要的工具并不能在所有类型的滚动视图\屏幕上工作
TouchAction touchAction = new TouchAction(driver); WebElement phone = driver.findElement(in.Repo.obj("apps.Phone")); WebElement contact = driver.findElement(in.Repo.obj("apps.Contacts")); touchAction.press(phone) .waitAction(200) .moveTo(contact) .release() .perform();
语法:
driver.executeScript("client:client.swipeWhileNotFound(\"direction\", offset, time);
从屏幕边框上滑动500 of的示例:
driver.executeScript("experitest:client.swipe(\"Up\", 0, 500)");
参数:
方向:进行滑动的方向(上、下、左、右)偏移:在屏幕上开始滑动时间的位置:滑动的持续时间(下=更快的滑动)
请注意
值(时间\偏移)通常是从设备屏幕大小(例如-
int offset = driver.manage().window().getSize().getHeight() / 2; // start from mid screen
int time = driver.manage().window().getSize().getHeight() * 0.3; // just an example
希望这能帮上忙
诚挚的问候,
尤金
https://stackoverflow.com/questions/55307113
复制相似问题