javascript - 如何使用没有唯一 ID、类、包或资源 ID 的 selenium & Appium 分割元素?

标签 javascript android selenium appium appium-android

我正在尝试检测是否从短信中收到了预期的回复。所以我需要访问收到的文本的 TextView 。我遇到的问题是我想不出一种方法让司机知道我需要收到的文本而不是发送的文本。

this first image of the ui selector shows that the sent text is highlighted here it shows the id, class, package, and resourse-id (which is out of frame)

in the second image of the ui selector shows that the received text is highlighted here it shows the id, class(out of frame), package, and resourse-id (which is out of frame)

所有属性值都匹配预期的文本值。我怎样才能让 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/

相关文章:

java - sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 通过 Selenium 和 Java 使用 findElement(By.className())

javascript - Protractor 的等价物被显示

python - Selenium 错误 - platform_sensor_reader_win.cc(242)]

javascript - javascript 中的类和 'access modifiers'

javascript - 使用 document.execCommand ('copy' 复制到剪贴板)因大文本而失败

android - 棉花糖及更高版本中折叠工具栏的问题

android - 如何使用 Monitor (DDMS) 工具调试应用程序

javascript - 如何获取时区偏移 ±hh :mm in javascript?

javascript - 如何使用 Jest 和 enzyme 为调用另一个函数的函数编写测试?

android - Dagger 2 : No implementation generated for component interface