【问题标题】:Unable to select the side menu button in TestNG (Appium, Android)无法在 TestNG(Appium、Android)中选择侧面菜单按钮
【发布时间】:2019-05-07 20:18:04
【问题描述】:

The red box contains the button i want to access using driver我是新手,但据我搜索,没有通用的方式来单击应用程序的侧边栏。

我目前正在尝试测试 Piazza 应用程序(大学作业)。首先,菜单/列表项没有任何 resource_id,我尝试过的方法对我不起作用。谁能指导我选择出现在侧栏上的此类按钮

所有评论的行都是我已经尝试过的现有在线解决方案。

 @BeforeSuite
  public void setupAppium() throws MalformedURLException {
        final String URL_STRING = "http://0.0.0.0:4723/wd/hub";  
        url = new URL(URL_STRING);
        capabilities = new DesiredCapabilities();
        capabilities.setCapability(MobileCapabilityType.DEVICE_NAME,"Android Device");
        capabilities.setCapability(MobileCapabilityType.APP, "/Users/nomi/Desktop/piazza.apk");
        capabilities.setCapability(MobileCapabilityType.NO_RESET, true);
        capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "UiAutomator2");
        driver = new AndroidDriver<MobileElement>(url, capabilities);
        driver.resetApp();
  }




  @Test ( enabled=true) public void logIn() throws InterruptedException   {

      driver.findElement(By.id("com.piazza.android:id/Login_editText_email")).sendKeys("l154053@lhr.nu.edu.pk");
      driver.findElement(By.id( "com.piazza.android:id/Login_editText_password")).sendKeys("viscabarca");
      driver.findElement(By.id( "com.piazza.android:id/Login_button_login" )).click();


  }




  @Test (enabled=true) public void getList() throws InterruptedException {
      //driver.findElementsByAccessibilityId("Open navigation drawer").get(0).click();
      //driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
      //driver.findElement(By.xpath("//*[@content-desc='"+"Open drawer"+"']")).click();
      // driver.manage().timeouts().wait(2);
      // driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);

        //driver.findElement(By.id( "com.piazza.android:id/AddClassMenu_addButton" )).click();
          //List<MobileElement> list = driver.findElements(By.id("com.piazza.android:id/list"));
          //list.get(0).click();
          //  System.out.print(list.size());
          //List nameOfList = driver.findElements(By.id("id of relative layout"));
        List<MobileElement> list = driver.findElements(By.id("com.piazza.android:id/list"));
          //list.get(0).click();
    System.out.print(list.size());
      }



}

get list 函数中的 list.size() 返回 size=0 它在登录函数之前执行。我使用了depends关键字,但它仍然返回0。此外,我不知道这个id正在获取什么列表。

【问题讨论】:

  • Nomii,欢迎来到 SO。您能否向我们提供您从中获取打印屏幕的页面的xml page source?这将极大地帮助我们为您提供解决方案。

标签: appium appium-android testng-eclipse


【解决方案1】:

由于元素中有content desc,因此您可以使用findElementByAccessibilityId()访问该元素。

driver.findElementByAccessibilityId("Open Navigation drawer")click();

我建议你使用 Appium Desktop Inspector 而不是 uiautomatorviewer。它会显示元素的任何唯一 id 以及 xpath。

【讨论】:

    猜你喜欢
    • 2017-07-09
    • 2015-10-05
    • 2019-01-26
    • 1970-01-01
    • 2020-02-25
    • 1970-01-01
    • 1970-01-01
    • 2014-07-22
    • 1970-01-01
    相关资源
    最近更新 更多