我正在尝试检测是否从短信中收到了预期的回复。所以我需要访问收到的文本的 TextView 。我遇到的问题是我想不出一种方法让司机知道我需要收到的文本而不是发送的文本。
所有属性值都匹配预期的文本值。我怎样才能让 appium 知道我需要检查哪一个? 我在想访问另一个元素中的一个元素的东西,代码 ID 假设是这样的:
await driver.waitForElementById('com.android.mms:id/msg_list_item_recv', 30000, function (err, data) {})
.elementById('com.android.mms:id/text_view', function (err, data){})
.textPresent('key text value', function (err, data) {});
如有任何帮助,我们将不胜感激。
最佳答案
If you can ask developers to update id of send text it will be best to do this, as currently there is same id for sent and received text . If this is not possible you can try this .
@FindBy(id = "com.android.mms:id/text_view")
private List<WebElement> messagelist;
for (int i=0;i<messagelist.size();i++)
{
if(messagelist.get(i).gettext().contentEquals("sendtext"))
{
// then i+1 is your received text
messagelist.get(i+1).gettext().contentEquals("recievedText")
}
}
关于javascript - 如何使用没有唯一 ID、类、包或资源 ID 的 selenium & Appium 分割元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48591905/