【问题标题】:How to Scroll on a Windows app using Appium and WebDriverIO?如何使用 Appium 和 WebDriverIO 在 Windows 应用程序上滚动?
【发布时间】:2021-11-27 21:59:27
【问题描述】:

我正在使用 Appium 和 WebDriverIO 在 Windows 应用程序上运行一些测试自动化。我需要滚动应用程序的某个部分,但不知道该怎么做。

我已尝试利用 WebDriverIO's scrollIntoView() method,但我收到了无法代理错误(可能是因为 WinAppDriver 不处理此方法?)

我也试过browser.touchScroll(xOffset: int, yOffset: int, string?:ElementID,但我对最后一个参数感到困惑。为了与 UI 元素交互,我一直在使用accessibilityID 选择器方法('~')。但参数只是要求一个字符串,而不是一个元素。我试过使用~,也只是输入元素的accessibilityID,但没有找到元素。

有人有什么想法可以帮助我吗?我会很感激的!

【问题讨论】:

  • 我也试过.moveTo(),但我得到了同样的错误。 “错误:处理命令时发生未知的服务器端错误。原始错误:无法代理。代理错误:请求失败,状态码为 501”

标签: automated-tests webdriver appium webdriver-io winappdriver


【解决方案1】:

也许这种方法适用于您的 Windows 应用程序,这对于向下滚动非常有效,直到 MobileElement 在 Appium 的屏幕中可见。您所要做的就是在 scrollAndFind(...); 中提供您的 MobileElement,它会神奇地滚动并找到它。

    public static void scrollAndFind(MobileElement element) {
        WebDriverWait wait = new WebDriverWait(driver, 2);

        int startX = (int) ((driver.manage().window().getSize().getWidth()) * 0.50);
        int endX = (int) ((driver.manage().window().getSize().getWidth()) * 0.50);
        int startY = (int) ((driver.manage().window().getSize().getHeight()) * 0.80);
        int endY = (int) ((driver.manage().window().getSize().getHeight()) * 0.20);

        int max = 10;
        boolean found = false;

        while (max > 0 && !found) {

            try {
                wait.until(ExpectedConditions.elementToBeClickable(element));
                found = true;

            } catch (Exception e) {
                new TouchAction<>(driver)
                        .press(PointOption.point(startX, startY))
                        .waitAction(WaitOptions.waitOptions(Duration.ofSeconds(1)))
                        .moveTo(PointOption.point(endX, endY))
                        .release()
                        .perform();
                max--;
            }
        }
    }

【讨论】:

    猜你喜欢
    • 2020-06-27
    • 2018-08-23
    • 2017-06-19
    • 1970-01-01
    • 2020-02-06
    • 2015-09-01
    • 2021-07-31
    • 2022-09-23
    • 2016-08-28
    相关资源
    最近更新 更多