如何使用appium java在hybdrid应用程序中垂直滚动

时间:2018-03-02 09:32:19

标签: android webview appium

enter image description here

我正在自动化混合应用程序。我想点击在页面上看不到的退出,因此我需要向下滚动才能点击它。我正在尝试下面的代码,但它没有工作,我使用Java客户端5.0.4 Appium服务器1.7.2和selenium 3.9.1和Java jdk版本1.8.0_161。任何人都可以帮忙

JavascriptExecutor js = (JavascriptExecutor)driver;
        HashMap<String, String> scrollObject = new HashMap<String, String>();
        scrollObject.put("direction", "down");
        js.executeScript("mobile: scroll", scrollObject); 
        do 
        {
        try{
        ele1.click();
        break;
        }
        catch(Exception e){
            js.executeScript("mobile: scroll", scrollObject); 
        }
        } while(true);

1 个答案:

答案 0 :(得分:-3)

查看此链接。我没有将它用于混合应用程序,但它可能会帮助你。它提供了使用Android Driver垂直滚动页面的解决方案  http://www.qaautomated.com/2016/02/how-to-scroll-in-appium.html

我尝试过这段代码,点击屏幕上看不到的对象。你可以试试这个。

MobileElement abc = (MobileElement) driver.findElement(MobileBy.AndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView("
                  +"new UiSelector().text(\"Country\"));"));
          abc.click();

将“Country”替换为您的text或resource-id。检查此链接以了解如何使用UiSelector,这有助于我找到此解决方案。 http://www.automationtestinghub.com/uiselector-android/