在Android上找不到XPath
使用在Android上找不到XPath,android,selenium,xpath,appium,Android,Selenium,Xpath,Appium,使用Appium、UIAutomatoViewer和安卓5.1 你能帮我定位元素的XPath吗。我需要从DVR盒(本例中为客厅,DVR1)中获取文本。我尝试了不同的组合,但还是没有运气 我无法使用资源id,因为对于RelativeLayout[0]和RelativeLayout[1]它们是相同的。我也不能用文本搜索页面,因为文本是动态的(DVR框会改变)。我认为唯一的解决方案是XPath 以下是我所做的: 但到目前为止,我的解决方案都不起作用 我无法使用“资源id”,因为对于Relati
Appium
、UIAutomatoViewer
和安卓5.1
你能帮我定位元素的XPath吗。我需要从DVR盒(本例中为客厅,DVR1)中获取文本。我尝试了不同的组合,但还是没有运气
我无法使用资源id
,因为对于RelativeLayout[0]
和RelativeLayout[1]
它们是相同的。我也不能用文本搜索页面,因为文本是动态的(DVR框会改变)。我认为唯一的解决方案是XPath
以下是我所做的:
但到目前为止,我的解决方案都不起作用
我无法使用“资源id”,因为对于RelativeLayout[0]和
相对论他们是一样的
您仍然可以使用资源ID
创建列表
并使用索引访问元素。在您的情况下,类似这样的情况:
List<WebElement> dvrList = driver.findElementsById("<id of the list element"); //creates a list of elements with same id
String text = dvrList.get(1).getText(); //this gives you text of 2nd element on list (base index 0)
编辑:-
Correct XPath = //android.widget.RelativeLayout[1]/android.widget.RelativeLayout[1]/android.widget.TextView[1]
对于属性部分的元素,请尝试使用
appium inspector
中显示的XPath。非常感谢。我使用的是UIAtomatorviewer,不知道在appium inspector中可以看到完整的XPath。UIAtomatorviewer没有此选项,但找到了正确的Xpath:WebElement drv=driver.findElement(By.Xpath(“//android.widget.RelativeLayout[1]/android.widget.RelativeLayout[1]/android.widget.TextView[1]”);drv.getText();希望appium检查员能帮助:)
AndroidElement d = (AndroidElement)
driver.findElementByXPath("//RelativeLayout[0]/TextView[0]");
List<WebElement> dvrList = driver.findElementsById("<id of the list element"); //creates a list of elements with same id
String text = dvrList.get(1).getText(); //this gives you text of 2nd element on list (base index 0)
WebElement dvrItem = driver.findElementByXPath("//android.widget.ListView[0]/android.widget.RelativeLayout[0]/android.widget.RelativeLayout[0]/android.widget.TextView[0]");
String text = dvrItem.getText();
Correct XPath = //android.widget.RelativeLayout[1]/android.widget.RelativeLayout[1]/android.widget.TextView[1]