【问题标题】:Appium cannot convert webelement list to arraylist of hashmapAppium 无法将 webelement 列表转换为 hashmap 的数组列表
【发布时间】:2017-02-02 07:07:46
【问题描述】:

我想在 listview 中显示来自 sqlite db 的数据。 我正在以数组列表格式(ArrayList>)获取数据。所以我希望该数组列表值显示在列表视图中。 这里 list 是我的列表视图 ID。

 driver.findElement(By.id("com.example.project:id/list"));

我在谷歌搜索并得到了这个

List<WebElement> list =  driver.findElement(By.id("com.example.project:id/list"));

但我想要这样

ArrayList<HashMap<String, Object>> list = driver.findElement(By.id("com.example.project:id/list"));

但我收到编译时错误,例如 appium 获取错误无法将 ArrayList> 转换为 List

所以在 谁能帮帮我!

【问题讨论】:

    标签: android testing appium


    【解决方案1】:

    driver.findElement 将返回一个 WebElement(带有您的 id 的元素)。

    如果您的 id 应用于多个元素,那么您想使用(注意额外的 s):

    List list =  driver.findElements(By.id("yourId"));
    

    如果你真的想强制转换到 List 你可以这样做:

    List<WebElement> list =  (List<WebElement>)(List) driver.findElements(By.id("yourId"));
    

    并添加 @SuppressWarnings("unchecked") 以使警告停止出现关于未检查演员表的警告

    对于 ArrayList >,我不知道你想在 String 和 Object 中放置什么

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-18
      • 2018-01-06
      • 1970-01-01
      • 2017-02-06
      • 2017-10-05
      • 1970-01-01
      • 1970-01-01
      • 2017-06-11
      相关资源
      最近更新 更多