【问题标题】:scroll to content description text滚动到内容描述文本
【发布时间】:2019-12-13 16:30:51
【问题描述】:

我一直在尝试寻找方法滚动 gmail 的原生 android 应用程序,以通过其内容描述文本找到特定的电子邮件

但是我没有运气,我在这里尝试使用这个命令:

String content = "Unread";

driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().textContains(\""+content+"\").instance(0))");

但这所做的只是滚动浏览所有内容。

我需要一个可以滚动以通过内容描述文本而不是显示文本来查找元素的命令。

有人可以帮忙吗?谢谢。

【问题讨论】:

    标签: java android automation appium


    【解决方案1】:

    我建议改用mobile:shell 命令,示例代码类似于:

    int startX = 0; //change
    int endX = 0;   //these
    int startY = 0; //to match your
    int endY = 0;   //swipe direction
    Map<String, Object> params = new HashMap<>();
    params.put("command", "input");
    params.put("args", Lists.newArrayList("swipe", startX,
            startY, endX, endY));
    
    while (driver.findElements(By.xpath("//*[contains(@content-desc,'Unread Gogi')]")).size() == 0) {
        driver.executeScript("mobile: shell", params);
    }
    

    替代选项是使用通过SeeTest Appium Extensions 提供的SwipeWhileNotFound 命令:

    seetest.swipeWhileNotFound("Down", 0, 2000, "NATIVE", "seetest.swipeWhileNotFound("Down", 0, 2000, "NATIVE", "xpath=//*[contains(@content-desc,'Unread Gogi')]", 0, 1000, 5, true)", 0, 1000, 5, true)
    

    【讨论】:

      【解决方案2】:

      您可以改用TouchAction,我尝试使用另一个locator

      这是我的意思的定位器:

      By.xpath -> //*[contains(@content-desc,'Unread')]
      

      我尝试获取定位器的xy的值,假设下面的代码要滚动到第一个定位器。

      if(driver.findElements(By.xpath("//*[contains(@content-desc,'Unread')]")).size()>0) {
          //the first element contains Unread
          WebElement elemnt = driver.findElements(By.xpath("//*[contains(@content-desc,'Unread')]")).get(0);
      
          //get x y
          int x = elemnt.getLocation().getX();
          int y = elemnt.getLocation().getY();
      
          //try to move
          TouchAction action = new TouchAction(driver);
          action.press(x, y).moveTo(x+50, y).release().perform();
      
          //here you can click the element
          elemnt.click();
      }
      

      希望这会有所帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-03-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-12-19
        相关资源
        最近更新 更多