【问题标题】:How to get text of specific element - Xamarin UI Test如何获取特定元素的文本 - Xamarin UI 测试
【发布时间】:2016-11-08 07:38:36
【问题描述】:

我有:

[TextView] id:“MonthValue”文本:“11”

我想将文本作为 id 的字符串 MonthValue

【问题讨论】:

  • 我需要:“11”作为字符串

标签: c# android xamarin uitest xamarin.uitest


【解决方案1】:

只需使用查询的Text 属性:

app.Query(c => c.Id("MonthValue").Text

参考:https://developer.xamarin.com/api/property/Xamarin.UITest.Queries.AppResult.Text/

【讨论】:

    【解决方案2】:

    想要更新吉姆的答案。 app.Query 返回一个数组,所以我们不能使用 app.Query(c => c.Id("MonthValue")).Text 本身。例如,我们应该使用app.Query(c => c.Id("MonthValue"))[0].Text

    【讨论】:

      【解决方案3】:

      app.Query(c => c.Id("MonthValue").Text("11")) 应该这样做

      【讨论】:

      • 是的,但我必须得到这个值,因为我可以通过 +/- 改变这个值。 ……应该像什么: String x = app.Query(c => c.Id("MonthValue").getText())
      • AppResult 有一个 Text 属性,所以试试 app.Query(c => c.Id("MonthValue")).Text。 developer.xamarin.com/api/property/…
      【解决方案4】:

      我也遇到了同样的问题,虽然我通过Repl() 命令通过调试得到了解决方案。 尝试像这样使用索引位置:

      app.Query(c=>c.Id("NoResourceEntry-8"))[0].Text
      

      类似地,你可以使用相同的类:

      app.Query(c=>c.Class("LabelRenderer"))[0].Text
      

      Class("LabelRenderer") 的查询得到 2 个结果。 所以在上面的例子中,你可以看到它给了你 2 个结果,但是你必须对特定的结果使用 index。

      【讨论】:

        猜你喜欢
        • 2017-09-29
        • 2020-03-01
        • 2016-07-29
        • 2016-12-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多