首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用7.0.0在appium中使用上下滑动/向下滚动?

如何使用7.0.0在appium中使用上下滑动/向下滚动?
EN

Stack Overflow用户
提问于 2019-03-22 20:08:19
回答 2查看 2.6K关注 0票数 0

这是我的代码,不工作的代码和控制台发送如下: java.lang.ClassCastException:无法强制转换com.sun.proxy.$Proxy18到org.openqa.selenium.remote.RemoteWebElement

我需要滑动/向下滚动。

代码语言:javascript
运行
复制
TouchAction swipe = new TouchAction(ApplicationLauncherAndroid.driver)
.tap(element(lblImagen))// first initialElement
.waitAction(waitOptions(Duration.ofMillis(2000)))
.moveTo(element(elementoFinal)) final Element
.release();
swipe.perform();
EN

回答 2

Stack Overflow用户

发布于 2019-03-23 16:42:51

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

代码语言:javascript
运行
复制
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导入触摸操作

票数 1
EN

Stack Overflow用户

发布于 2019-03-23 20:49:27

@Pedro Perez Aballay,嗨。我建议使用以下备选方案:

(只适用于仪器化的应用程序-以及ListViews) --使用应用程序的内部API,类似于scrollIntoView在web上的工作方式,尽管它需要的工具并不能在所有类型的滚动视图\屏幕上工作

  • 备选方案B: TouchAction -例如 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();
  • 选项C:client - SwipeWhileNotFound
  • 选项D: executeScript并指定要执行滑动动作

语法:

代码语言:javascript
运行
复制
driver.executeScript("client:client.swipeWhileNotFound(\"direction\", offset, time);

从屏幕边框上滑动500 of的示例:

代码语言:javascript
运行
复制
driver.executeScript("experitest:client.swipe(\"Up\", 0, 500)");

参数:

方向:进行滑动的方向(上、下、左、右)偏移:在屏幕上开始滑动时间的位置:滑动的持续时间(下=更快的滑动)

请注意

值(时间\偏移)通常是从设备屏幕大小(例如-

代码语言:javascript
运行
复制
int offset = driver.manage().window().getSize().getHeight() / 2; // start from mid screen
int time = driver.manage().window().getSize().getHeight() * 0.3; // just an example

希望这能帮上忙

诚挚的问候,

尤金

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55307113

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档