scrollIntoView не работает в appium для просмотра журнала прокрутки. Не выбрасывает такое исключение элемента после одного / двух ударов - PullRequest
0 голосов
/ 18 января 2020

Generi c функция для прокрутки, где scrollablelist - это локатор вида прокрутки, в котором мы должны прокручивать

public void scrollToElementWithText(RemoteWebDriver driver, String scrollableList, String text) {

        MobileElement element = (MobileElement) driver
                .findElement(MobileBy.AndroidUIAutomator("new UiScrollable(new UiSelector().resourceId(\""
                        + scrollableList + "\")).scrollIntoView(" + "new UiSelector().text(\"" + text + "\"))"));
    }

1 Ответ

0 голосов
/ 18 января 2020

Вы можете попробовать следующий код в существующем коде scrollable(true).instance(0))

Добавить нужную возможность UiAutomator2, если вы используете appium в качестве automation движка.

capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "UiAutomator2");

Теперь используйте функции ниже, если у вас есть идентификатор элемента и индекс как 0, поскольку на странице есть один элемент.

public void scrollByID(String Id, int index) {

        try {

             driver.findElement(MobileBy.AndroidUIAutomator("new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().resourceId(\""+Id+"\").instance("+index+"));")); 

        } catch (Exception e) {
           e.printStackTrace();
        }
    }

Прокрутка с использованием текста

public void scrollByText(String menuText) {

        try {

             driver.findElement(MobileBy.AndroidUIAutomator("new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().textMatches(\"" + menuText + "\").instance(0));")); 
        } catch (Exception e) {
           e.printStackTrace();
        }
    }

Прокрутка с помощью размера экрана:

public void scrollToBottom() {

      int  x = driver.manage().window().getSize().width / 2;
      int start_y = (int) (driver.manage().window().getSize().height * 0.2);
      int end_y = (int) (driver.manage().window().getSize().height * 0.8);
        TouchAction dragNDrop = new TouchAction(driver)
                        .press(PointOption.point(x,start_y)).waitAction(WaitOptions.waitOptions(Duration.ofMillis(500)))
                        .moveTo(PointOption.point(x, end_y))
                        .release();
        dragNDrop.perform();
    }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...