Appium 无法使用资源 ID 识别元素

问题描述 投票:0回答:3

Appium 无法使用 id 定位器(resource-id)来识别元素,但我们可以使用 Accessibility Id 定位器来识别相同的元素。

请参阅附图。enter image description here

appium appium-android
3个回答
1
投票

您的 Appium 版本是什么?可以用Appium Inspector打开看看和UI Automator Viewer有没有区别?

无论如何...试试这个

#Can't see at your screenshot the whole resource-id so I put what I see.
driver.find_element_by_xpath("//android.view.View[@resource-id='rptRole__ctl0_rptCommunicationlt...']")

#You could also try these two options:
driver.find_element_by_xpath("//android.view.View[@content-desc='1_gr_selected_stores_flex_update.xls']")

driver.find_element_by_xpath("//android.view.View[@text='1_gr_selected_stores_flex_update.xls']")

如果这些都不起作用,您将必须提供更多信息


1
投票

Appium 不支持 ID 中包含 $ 之类的内容。可以贴一下完整的ID吗? 请使用 findElementById 方法尝试如下:

driver.findElementById("alertTitle");

如果不起作用,请使用类名查找元素并使用索引来定位元素。

List<WebElement> allElements=driver.findElementsByClassName("android.view.View");

并使用上面列表中的索引获取元素。

WebElement yourElement= allElements.get(Required_Index);

1
投票

下面的代码有效。

driver.findElementsByXPath("//android.view.View[contains(@resource-id,'rptRole')]").click();

© www.soinside.com 2019 - 2024. All rights reserved.