首页 > 解决方案 > 在 Xamarin 自动化 UI 测试中按索引从 ListView 获取元素

问题描述

在此处输入图像描述我有一个ListView他的自动化 ID = List,我想点击第二个元素。

我怎样才能用他的索引点击他?

app.tap((automationId)[1]) //?

标签: c#listviewautomationautomated-testsxamarin.uitest

解决方案


就我而言,我已将 AutomationId 分配给侧 DataTemplate 中的第一个视图。所以我可以按索引点击特定的单元格。

这将获取 ListView 中的所有单元格:

app.Tap(c => c.Marked("TeamListCell"));   

您可以像这样按索引点击特定项目:

app.Tap(c => c.Marked("TeamListCell").Index(0));   

推荐阅读