0

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

请参考附图。在此处输入图像描述

4

3 回答 3

0

如果您的 ID 中有 $ 之类的,Appium 不支持。能不能发下你的全ID。请使用 findElementById 方法尝试如下:

driver.findElementById("alertTitle");

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

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

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

WebElement yourElement= allElements.get(Required_Index);
于 2017-12-08T09:54:56.757 回答
0

你的 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']")

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

于 2017-12-05T10:39:27.510 回答
0

下面的代码有效。

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

于 2017-12-13T06:58:04.330 回答